我收到類型的未處理的異常列表<T>。新增對象的類型給出了「System.NullReferenceException」的未處理的異常出現在UgenityAdministrationConsole.exe
「System.NullReferenceException」發生在 UgenityAdministrationConsole.exe
附加信息:未將對象引用設置爲 對象的實例。
這發生在我的類構造函數中。
這裏是我的代碼:
public static object dummyObject = new object(); // create a dummy object to use for initializing various things
public class EntityValuesClass
{
public List<EntityValue> EntityValues { get; set; }
public EntityValuesClass(EntityType _entType)
{
Type t;
PropertyInfo[] propInfoArray;
EntityValue entValue = new EntityValue();
t = entityTypeToType[_entType];
propInfoArray = t.GetProperties();
foreach (PropertyInfo propItem in propInfoArray)
{
entValue.FieldName = propItem.Name;
entValue.FieldValue = dummyObject;
EntityValues.Add(entValue); <------ this is where the error is happening
}
}
}
public class EntityValue
{
public string FieldName { get; set; }
public object FieldValue { get; set; }
}
您沒有將對象引用(EntityValues)設置爲對象的實例(新List
2013-02-23 21:31:11
http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net – 2013-02-23 21:32:01