Home

Null-reference exceptions

I've encountered two odd-ball scenarios. I'm posting them together because the exception's call-stacks are the same, and it might be the same underlying issue.

Running as a "program"...


//SCENARIO #1
#define NONEST

void Main()
{
	new SomeClass().Dump();
}

public interface ISomeInterface { }

class SomeClass : ISomeInterface { }


and, again, running as a "program"...


//SCENARIO #2
void Main()
{
	new SomeInternalClass().Dump();
}

public interface ISomeInterface { }

class SomeInternalClass : ISomeInterface { }

public class SomePublicClass { }

public static class CalculationExtensions
{
	public static SomePublicClass DoSomething( this int i ) { return default(SomePublicClass); }
}



Both scenarios result in...

Object reference not set to an instance of an object.

at System.Linq.Enumerable.<>c__DisplayClassf`1.b__e(TSource x)
at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.d__0.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)



Not too much a bother, but did have to spend some time trimming away from an initially large codebase to get a better grasp on it. Accessibility is certainly a factor. That is, changing some of the internal classes to public in the above examples will circumvent the error.

Reproducible in both 4.47.00 and 4.47.05 - haven't tried any others.

Comments

Sign In or Register to comment.