Result from a one-item query result isn't always available

Developer
Dec 6, 2010 at 1:33 PM

I'm doing some simple queries against the client and I get a situation where the count of the result is 1, which I expect, but when I try to access the result via result.ElementAt(0) or result.First() I get a object reference not set to an instance of an object exception.

When I debug it though, I can find a populated resource object in the client, but something to do with the Enumeration mechanism isn't working properly.

Has anyone else experienced this or know what the problem is?

It looks like the problem could be in Microsoft.ResourceManagement.Client.EnumerationResultEnumerator.MoveNext()

Developer
Dec 6, 2010 at 2:15 PM

Ah, actually this is a gotcha in terms of usability. There's nothing wrong with the client...

I was getting the result and then checking if it had results by checking result.Count() which actually fires the enumerator MoveNext() and moves the enumeration on.

By changing my code to result.FirstOrDefault() and then check for null I know if I have a result and have the result at the same time.

Getting carried away with Linq it seems.