GCP c# 'Object reference not set to an instance of an object.' 将对象添加到 NetworkInterfaces 列表时 <NetworkInterface>
GCP c# 'Object reference not set to an instance of an object.' when adding object to NetworkInterfaces List<NetworkInterface>
我要经典
Object reference not set to an instance of an object
将 Google.Apis.Compute.v1 NetworkInterface 对象添加到 NetworkInterface 的列表时出错。
Google.Apis.Compute.v1.Data.Instance requestBody = new Google.Apis.Compute.v1.Data.Instance();
requestBody.MachineType = "zones/us-east1-b/machineTypes/n1-standard-1";
requestBody.Name = "lolzorpbn";
requestBody.Scheduling = new Scheduling() { Preemptible = true };
NetworkInterface FailingNetworkObject = new NetworkInterface() { Name = "eth0", Network = "global/networks/default", AccessConfigs = new List<AccessConfig>() { new AccessConfig() { Type = "ONE_TO_ONE_NAT" , Name = "External NAT" } } };
requestBody.NetworkInterfaces.Add(FailingNetworkObject);
对象已实例化,在检查错误时未提供更多详细信息。
实例化您自己的 IList<NetworkInterface>
,并将其分配给 属性:
Google.Apis.Compute.v1.Data.Instance requestBody = new Google.Apis.Compute.v1.Data.Instance();
requestBody.NetworkInterfaces = new List<NetworkInterface>
{
new NetworkInterface { ... }
};
我要经典
Object reference not set to an instance of an object
将 Google.Apis.Compute.v1 NetworkInterface 对象添加到 NetworkInterface 的列表时出错。
Google.Apis.Compute.v1.Data.Instance requestBody = new Google.Apis.Compute.v1.Data.Instance();
requestBody.MachineType = "zones/us-east1-b/machineTypes/n1-standard-1";
requestBody.Name = "lolzorpbn";
requestBody.Scheduling = new Scheduling() { Preemptible = true };
NetworkInterface FailingNetworkObject = new NetworkInterface() { Name = "eth0", Network = "global/networks/default", AccessConfigs = new List<AccessConfig>() { new AccessConfig() { Type = "ONE_TO_ONE_NAT" , Name = "External NAT" } } };
requestBody.NetworkInterfaces.Add(FailingNetworkObject);
对象已实例化,在检查错误时未提供更多详细信息。
实例化您自己的 IList<NetworkInterface>
,并将其分配给 属性:
Google.Apis.Compute.v1.Data.Instance requestBody = new Google.Apis.Compute.v1.Data.Instance();
requestBody.NetworkInterfaces = new List<NetworkInterface>
{
new NetworkInterface { ... }
};