Type Initializer Error on running LINQ query

Posts   
 
    
Sandumone1
User
Posts: 27
Joined: 28-Oct-2009
# Posted on: 03-Nov-2009 23:18:01   

The database is : SQL server Runtime version : LLBLgen 2.6 Final release : Oct 9 2009.

The type initializer error is coming on running thsi LINQ query.

LinqMetaData metaData = new LinqMetaData(); var q = from c in metaData.UiFlowMachine where c.MachId == 283 select c;

the execution of this query is not giving any data , but an error below.

The error is :

StackTrace

" at uFACTS.BusinessEntities.FactoryClasses.EntityFactoryFactory..cctor() in C:\uFACTSFramework\Service Tier\Business Logic\uFACTS.BusinessEntities\_generated\FactoryClasses\EntityFactories.cs:line 1883" string

Exception Thrown :

  • base {"The type initializer for 'uFACTS.BusinessEntities.FactoryClasses.EntityFactoryFactory' threw an exception."} System.SystemException {System.TypeInitializationException}

  • [System.NullReferenceException] {"Object reference not set to an instance of an object."} System.NullReferenceException

The line 1883 is in this method in EntityFactories.

/// <summary>Initializes the <see cref="EntityFactoryFactory"/> class.</summary> static EntityFactoryFactory() { Array entityTypeValues = Enum.GetValues(typeof(uFACTS.BusinessEntities.EntityType)); foreach(int entityTypeValue in entityTypeValues) { IEntity dummy = GeneralEntityFactory.Create((uFACTS.BusinessEntities.EntityType)entityTypeValue); _factoryPerType.Add(dummy.GetType(), dummy.GetEntityFactory()); } }

I saw some links talking about the EntityType Enum and changing it and all. Could not understand what to do exactly.

The unknown entitytype is sent when we are using LINQ to LLBLGen pro .

Can you please suggest what to do?

I tried with different entities and the result is the same.

thanks sam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2009 04:13:35   

Hi Sam,

Is there something special we should know about your code? For example: Did you change/modify/add anything on the base generated code? Also, please take a look at these forum guidelines so we can help you better: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=12769

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 04-Nov-2009 09:47:50   

indeed, you did add a value to the EntityType enum?

Frans Bouma | Lead developer LLBLGen Pro
Sandumone1
User
Posts: 27
Joined: 28-Oct-2009
# Posted on: 04-Nov-2009 18:31:29   

I have not made any changes to the generated code. The only section generated for LINQ is Linq/LinqmetaData.cs file.

I read about the change in EntityType Enum , but i have not chnaged it .

Please help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 04-Nov-2009 18:52:39   

Could you please be specific which line the error is on? So which line of code is line 1883?)

Frans Bouma | Lead developer LLBLGen Pro
Sandumone1
User
Posts: 27
Joined: 28-Oct-2009
# Posted on: 05-Nov-2009 01:26:44   

IEntity dummy = GeneralEntityFactory.Create((uFACTS.BusinessEntities.EntityType)entityTypeValue);

is 1883

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 05-Nov-2009 10:06:53   

Sandumone1 wrote:

IEntity dummy = GeneralEntityFactory.Create((uFACTS.BusinessEntities.EntityType)entityTypeValue);

is 1883

Please put a breakpoint on that line, run the application in debug mode and step into GeneralEntityFactory.Create (or set a breakpoint there). It's likely th entityTypeValue given is not in the range of what's generated into GeneralEntityFactory.Create. This suggests you have generated code but some files were readonly and not overwritable. (as all code is generated in 1 go so everything matches).

Frans Bouma | Lead developer LLBLGen Pro