Most Likely Cause of the C# Error: "Non-static method requires a target"

I've encountered this error twice in the last two days, both times occurring while with a LINQ query and Entity Framework.

And, in both cases, the problem stemmed from using a null value within the LINQ. Ultimately, the problem was farther upstream and not with my LINQ query at all (though better use of a try-catch statement would've been smart). The problem was an object with a null value being passed into the method. Once I figured that out, it was fairly easy to step through the debugger and see where my object wasn't being set to a legitimate value.

So, if you get the error "Non-static method requires a target,", then verify that every value you're using within your LINQ statement contains a value, not a null.

See the following posts on the web for more information and resolution to this error.




Comments

Popular posts from this blog

Using Reference Aliases

List of Visual Studio Keyboard Shortcuts

Quick Example of System.IO.Abstractions Use