I hit a null reference exception when attempting to add a Dictionary<string,string>
to a List<Dictionary<string,string>>
variable. I'm unable to find the cause.
public class MyObject
{
public List<Dictionary<string, string>> ID_Name_List { get; set; }
}
MyObject obj1 = new MyObject();
Dictionary<string, string> ID_Name_Pair = new Dictionary<string, string>();
ID_Name_Pair.Add("1", "Jane");
List<Dictionary<string, string>> ID_Name_List_2 = new List<Dictionary<string, string>>(); //For Testing
ID_Name_List_2.Add(ID_Name_Pair); //SUCCESS
obj1.ID_Name_List.Add(ID_Name_Pair); //ERROR - System.NullReferenceException: 'Object reference not set to an instance of an object.'
My obj1.ID_Name_List
variable has the same List<Dictionary<string, string>>
type with ID_Name_List_2
Why did my obj1.ID_Name_List
hit an error while ID_Name_List_2
is successful?
Any help will be greatly appreciated