weird "type initializer" error

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 21-May-2006 09:58:16   

Any idea what this error could be:

The type initializer for "Agro.Datalayer.EntityClasses.ContractEntityBase" threw an exception. An attempt was made to load a program with an incorrect format. at Agro.Datalayer.EntityClasses.ContractEntityBase.get_Relations()

It's in an application which runs fine for days, an then suddenly produces this error ..

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 21-May-2006 11:43:42   

Relations is a static property, so when the first call to that class is made in your app, the code will then try to initialize ContractRelations as a class. That class might have corrupt IL which causes this. The error you get is typically a result of an internal C# compiler error. We've had it in the beta of v2 as well when there were a lot of statements generated in one method, which caused the C# compiler to emit corrupt IL. However in the relations class, there are just a couple of properties, one for each relation.

If you're using .NET 1.1, be sure you're using .NET 1.1 SP1 and recompile all code. Also, please check this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6040 it gives you ideas how to verify your assembly to see if it contains any corrupt IL code. Because of the issue with the early beta of v2, I did some research on this and it's in all cases a problem with the C# compiler which can be fixed by changing some code in the method which causes the problem, e.g. reordering statements. If you've ever done C++ programming, it's similar to the optimization bugs / issues which sometimes occured in VC++ 6.0 in release builds.

Frans Bouma | Lead developer LLBLGen Pro