I’m getting an object reference not set to an instance of an object error in the condition of a while loop and I don’t know what it’s happening. The code is:
while (ClassName.StaticDataTable == null || ClassName.StaticDataTable.Rows == null)
I tried to make the object names explanatory. I thought || was a short circuit operator so that if the first condition was true it wouldn’t evaluate the second one and that the error shouldn’t be coming from there. Any ideas on what is causing the error?
If you’re getting
null referenceexception onwhile (ClassName.StaticDataTable == null || ClassName.StaticDataTable.Rows == null)I think of for example:
ClassName == nullSo may be (just guess) for you would be enough to add one
||condition more in front of others already present, likewhile (ClassName == null || ClassName.StaticDataTable == null || ClassName.StaticDataTable.Rows == null)EDIT
There could be also a case if
StaticDataTableproperty not just returns a value but does something inside it which throwsnull reference exception.Try to dig into that property.Hope this helps.