I have the following VB.NET code:
Namespace Data
Public Module Part
Public function IsValidPart()
End Function
End Module
End NameSpace
Now, how do I call the IsValidPart method in the Part module? When I try to call the method, I get the following error:
The type initializer for ‘MyCompany.Lender.Data.Part’ threw an
exception. —> System.NullReferenceException: Object reference not
set to an instance of an object..
The problem code is not in your snippet. It is caused by an initialization of a variable in your module. A simple example of such a problem is:
You get a non-descript TypeInitializationException when the static constructor for the module runs. Which is code that the compiler generates to ensure the Example variable gets initialized. Unfortunately, the debugger doesn’t display a good diagnostic for this.
You can find the problem statement with Debug + Exceptions, tick the Thrown box for CLR exceptions.