An incorrect program error was discovered by the C# Entity Framework 4 Common Language Runtime? c# clr entity-framework linq


A "Common Language Runtime identified an incorrect program" error: how do you debug/fix it? What does it really imply, then?

I have two websites that are hosted on the same IIS 7.5 webserver, and I can deploy a C# MVC 2 web project to both of them (x64). The beta site is the second; the first is the live site (deployed using the Release configuration) (deployed using a new Beta configuration created just for this project).

There are two websites:

Default Website/my_app

When choosing from a paged list of purchase orders on the beta site, the "detected an incorrect program" error is raised. When performed on the live site, the exact same code works flawlessly. Why would it do that?

Edit: After setting up Visual Studio on the server, I identified the line that was causing the issue and the associated stack trace:

var list = ObjectContext.ObjectSet.AsQueryable();
int totalRecords = list.Count();
var paged = list.Skip((page > 0 ? page - 1 : 0) * rows).Take(rows);

And the exception message with stack trace is as follows:

{System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at System.Data.Entity.DynamicProxies.PurchaseOrderListVie_96479BFE9FA60F4C53137C56C1A1B2A11D90FF5AFFDC20383CC68E0A750792E3.set_Total(Decimal )
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 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.Shaper`1.SimpleEnumerator.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MyApp.Controllers.PurchaseOrderController.GetPurchaseOrderList(Int32 page, Int32 rows, String sidx, String sord) in C:\src\MyApp.2010\MyApp.UI\Controllers\PurchaseOrder\List.cs:line 11}

This updated information pinpoints the specific location of the issue but does not identify it. I'm hoping someone who is really familiar with Entity framework can clarify this:

System.Data.Entity.DynamicProxies.PurchaseOrderListVie_96479B_etc.set_Total(Decimal )

is the line that contains the mistake. Now that I've executed the query in SQL Management Studio, neither the result nor the value for Total were null. Why then did it have issues calling set Total()?

The POCO specifies the Total field (created by a T4 template) as follows:

[Decimal] [Required] [DisplayName("Total")]
public virtual decimal Total

The build configuration is the primary distinction between the live and beta sites. However, in both situations, "Any CPU" is selected for every single project.

Our whole fleet of servers and workstations is 64 bit. Could this be due to a difference in how the websites' IIS configurations are set up?

PEVerify just states, "All Classes and Methods Verified," when I try to execute it. How might PEVerify assist in solving this kind of issue?

By the way, I note that the headline of around 15 questions reads, "Common Language Runtime discovered an incorrect program error." My inquiry is not a duplication and differs from other inquiries with the same subject in a number of significant ways (and only one of those 15 is about Entity Framework too - the rest are about Reflection or TFS)

7/19/2011 9:15:36 PM

Accepted Answer

When I delivered a web application that used linq to entity 4 to our QA environment today, I encountered this problem. An IIS configuration on the Windows 2008 R2 server turned out to be the problem. The Enable 32-bit Applications option for the application pool was set to False under Advanced Settings. My program now functions exactly as it did on the development server, a Windows 2003 server, after I changed it to True. Hope this was helpful.

7/19/2011 5:34:40 PM

Popular Answer

This occurred for me when I expanded my entity model by a view. The designer sets the Entity Key attribute of each column to true by default. The problem disappears when I change it to false for all decimal/numeric columns. Tas

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow