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](Func
2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper
at lambda_method(Closure , Shaper ) at System.Data.Common.Internal.Materialization.Coordinator1.SimpleEnumerator.MoveNext() at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
1 source) ... more removed
at System.Linq.Enumerable.ToList[TSource](IEnumerable
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.
Try set the startup project to target 32bits, that should prevent the apparent 64-bit issue. And explain why it runs fine with MVC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With