C#实体框架4通用语言运行时检测到一个无效的程序错误? [英] C# Entity Framework 4 Common Language Runtime detected an invalid program error?

查看:573
本文介绍了C#实体框架4通用语言运行时检测到一个无效的程序错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何调试/修复一个通用语言运行时检测到一个无效的程序的错误?究竟是什么意思呢?

How do you debug/fix a "Common Language Runtime detected an invalid program" error? What exactly does it mean anyway?

我有一个可以部署到两个网站驻留在同一个C#MVC 2的Web应用程序IIS 7.5 Web服务器(64位)。一个是现场直播(使用Release配置部署),第二个是测试站点(使用只为这个项目创造了一个新的测试版的配置部署)。

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).

这两个网站是:

Default Website/my_app
Beta/my_app

在测试网站中选择采购订单的名单分页时,抛出了检测到无效的程序异常。当活动站点上运行完全相同的code完美的作品。为什么会这样?

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?

编辑:我在服务器上安装Visual Studio和发现,是造成问题和堆栈跟踪实际的行:

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 )

时发生错误的行。现在,我跑在SQL Management Studio中的查询,结果是不为空,且总不空两种。那么,为什么它有调用set_Total()?问题

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()?

这是该POCO如何定义总场(由T4模板生成的):

This is how the POCO defines the Total field (generated by a T4 template):

[Decimal] [Required] [DisplayName("Total")]
public virtual decimal Total
{
    get;set;
}

活和β-位点之间的主要区别是构建配置。但无论是配置有每一个项目设置为任何CPU。

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".

我们所有的开发机和服务器都是64位。莫不是网站的IIS配置之间的一些差异,是造成这个?

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?

我试着运行PEVerify - 但它只是说,所有的类和方法验证。如何与这种类型的问题PEVerify帮助?

I've tried running PEVerify - but it just says "All Classes and Methods Verified." How can PEVerify help with this type of problem?

BTW我可以看到,有大约在标题为通用语言运行时检测到一个无效的程序问题的15个问题。我的问题是不是重复,并有几个独特的功能,是从有类似标题的其他问题不同(只有那些15个是关于实体框架太 - 其余的都是关于反射或TFS)

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)

推荐答案

今天我遇到了这个问题,当我部署实施的LINQ to实体4到我们的QA环境中的Web应用程序。这个问题竟然是在Windows 2008 R2服务器上的IIS设置。在高级设置应用程序池,为使32位应用程序的设置被设置为False。我将它设置为True,现在我的应用程序的工作正如它正好是在Windows 2003服务器的开发服务器上。我希望这有助于。

I ran into this issue today when I deployed a web application implementing linq to entity 4 to our QA environment. The issue turned out to be an IIS setting on the Windows 2008 R2 server. Under Advanced Settings for the application pool, the setting for Enable 32-bit Applications was set to False. I set it to True and now my application works just as it did on the development server which happened to be a Windows 2003 server. I hope this helps.

这篇关于C#实体框架4通用语言运行时检测到一个无效的程序错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆