Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal as Primary Key works in Dev (Win7/64bit) but not in Production (Win2008R2/64bit) Common Language Runtime detected an invalid program

My Windows Service is a .NET application. The service has a dependency on my data access which uses EF 4.3 Code First. I am getting the following error when my service runs and attempts to access data.

Error occured in FullPurgeAndReplace(): System.InvalidProgramException: Common Language Runtime detected an invalid program. at System.Data.Entity.DynamicProxies.MOMInventoryItem_3ED5D5176D2C03867C62DD8E4381A882350CFD9CD931F3CD551623A6EF5C4D8E.set_Id(Decimal ) at lambda_method(Closure , Shaper ) at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper ) at System.Data.Common.Internal.Materialization.Coordinator
1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper1.SimpleEnumerator.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) ... more removed

On the SAME MACHINE I have a web application that depends on the same data access project and runs without issue. For that website in IIS I DO have Enable 32-bit applications checked for the respective Application Pool.

I have researched the problem and found that it MAY be related to the fact that the entity in the error (MOMInventoryItem) has a decimal primary key. I have no choice since I'm integrating with an existing system. However, that was supposedly a known issue with EF 4.0 from over a year ago and I would expect it to be resolved by now.

Here is some code from my Entity:

[Table("STOCK")]
public class MOMInventoryItem
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.None), Column("STOCK_ID")]
    public virtual decimal Id { get; set; }

Again, this works fine via an MVC app hosted in IIS but fails as a Windows Service, both on the same Windows 2008 R2 server. It also works on my DEV machine (Win7/VS11). What is my problem and how might I either resolve it permanently or work around it?

As always help is very much appreciated and reciprocated when possible.

like image 728
kingdango Avatar asked Sep 13 '12 13:09

kingdango


1 Answers

Try set the startup project to target 32bits, that should prevent the apparent 64-bit issue. And explain why it runs fine with MVC.

like image 183
leppie Avatar answered Nov 01 '22 13:11

leppie