How do you debug/fix a "Common Language Runtime detected an invalid program" error? What exactly does it mean anyway?
I have a C# MVC 2 web app that can deployed to two websites that reside on the same IIS 7.5 webserver (x64). One is the live site (deployed using Release configuration), the second is the beta site (deployed using a new Beta configuration created just for this project).
The two websites are:
Default Website/my_app
Beta/my_app
On the beta site when selecting a paged list of purchase orders, it throws the "detected an invalid program" exception. The exact same code when run on the live site works perfectly. Why would it do this?
Edit: I installed Visual Studio on the server and found the actual line that was causing the problem and the stack trace:
var list = ObjectContext.ObjectSet.AsQueryable();
int totalRecords = list.Count();
var paged = list.Skip((page > 0 ? page - 1 : 0) * rows).Take(rows);
And this is the exception message with stack trace:
{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 new info shows exactly where the problem is, but not what the problem is. Hopefully someone who knows Entity framework very well can shed light on this:
System.Data.Entity.DynamicProxies.PurchaseOrderListVie_96479B_etc.set_Total(Decimal )
Is the line where the error occurs. Now I ran the query in sql management studio and the result was not null, and Total was not null either. So why did it have a problem calling set_Total()?
This is how the POCO defines the Total field (generated by a T4 template):
[Decimal] [Required] [DisplayName("Total")]
public virtual decimal Total
{
get;set;
}
The main difference between the live and beta sites is the build configuration. But both of the configurations have every single project set to "Any CPU".
All our development machines and servers are 64 bit. Could there be some difference between the IIS configuration of the websites that is causing this?
I've tried running PEVerify - but it just says "All Classes and Methods Verified." How can PEVerify help with this type of problem?
BTW I can see that there are around 15 questions with "Common Language Runtime detected an invalid program problem" in the title. My question is not a duplicate and has several unique features that are different from the other questions that have a similar title (and only one of those 15 is about Entity Framework too - the rest are about Reflection or TFS)