Question : Object reference not set to an instance of an object.

Hi,
I am getting an error  "Object reference not set to an instance of an object." on the following highlighted source.

foreach (DataRow row in UploadAds.Rows)
            {
                AdParamSelector adParamSelector = new AdParamSelector();
                adParamSelector.criteriaId[0] = (long)row["AWKGoogleID"];

Thes suggestions are to use the "New" Keyword, which I believe I am in the previous statement "= new AdParamSelector();"
Also the help suggested to check to determine if the object is Nulls where I have checked that (long)row["AWKGoogleID"] is poulated and I am setting adParamSelector.criteriaId[0]
any suggestions?

Answer : Object reference not set to an instance of an object.

The most likely case is that your .criteriaId array has not been initialized to any given size.  Since (long)row["AWKGoogleID"] can represent at most one long you should initialize the adParamSelector.criteriaID array to size 1;

for...

adParamSelector.criteriaId = new long[1];

adParamSelector = new AdParamSelector();
 adParamSelector.criteriaId[0] = (long)row["AWKGoogleID"];

Random Solutions  
 
programming4us programming4us