System.NullReferenceException:对象引用未设置为对象的实例

时间:2019-07-26 15:05:52

标签: c# json.net

使用当前正在使用的这段代码,当我尝试在对象上输入数据并告诉该方法用数据返回对象时,我使用了上面提到的类将json映射到对象中,我得到了错误System.NullReferenceException :对象引用未设置为对象的实例。

public Resources GenerateResources()  
{  
//Here I create the Objects  
Tenant tenant = new Tenant();  
Resources resource = new Resources();  
DataBaseSettings data = new DataBaseSettings();  
Attributes attributes = new Attributes();  
DataBaseSettingsProperties prop = new DataBaseSettingsProperties();  

//Start adding data to the properties  
tenant.id = System.Guid.NewGuid().ToString();  
tenant.properties = null;  

data.Id = System.Guid.NewGuid().ToString();  
data.ResourceType = "databaseSettings";  
data.PackageInstanceId = System.Guid.NewGuid().ToString();  

attributes.serverName = "Automation2017";  
attributes.databaseName = "Automation-Live";  
attributes.authMode = "Windows";  
attributes.userName = "";  
attributes.password = "";  
attributes.mdfLocation = "F:/Data";  
atributes.ldfLocation = "F:Log";  
attributes.dbType = "Production";  

prop.attributes = attributes;  
data.properties = prop;  
resource.databaseSettings[0] = data;  //Here I get the error  
return resource;  
}

0 个答案:

没有答案