CLR detected an Invalid Program

2019-05-29 14:15发布

问题:

Need any help, ideas to figure out this issue.

We are working on an application that makes a call to SAP for posting some data using ERPConnect. We encounter the following issues in one of our Entity Framework call in our WCF service. We are using .NET4.0, Win 2008 Server.

The following information was included with the event:

exception in getting ****getrebateproposal**-****Common Language Runtime detected an invalid program.******   at System.Data.Entity.DynamicProxies.RebateProposal_E1004D9B0153012E0A7A09FC9B574872909349EC992253740AB3C066FC63CF4D.set_Id(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 CommercialTermsRepository.GetRebateProposalsAmountToPay(String rebateAgreement) in D:\Projects\TFS\CIT V2\DataModel\BusinessObjects\CommercialTermsRepository.cs:line 794
       at SAPInterface.RebateProposalService.SetZv41Data(List`1 uploadRebates) in D:\Projects\TFS\CIT V2\Server\UserService\RebateProposalService.svc.cs:line 187

回答1:

  1. Did you try running PEVerify on the exe/dll to see if there are any issues?
  2. Did you try running ngen on it to see if ngen fails?
  3. Can you post the failing code or a small repro of your issue?

And a few things to look for:

  • Is the lambda in a gigantic method? (that is, is it closing over a lot of values?) - Try to move it out so that this is not the case
  • Are you using a delegate type that has a COM object in the params or output? (I've had issues with that in the past)


回答2:

Did this ever get resolved? I'm running into a similar problem

InvalidProgramException: Common Language Runtime detected an invalid program.

The exception is occurring when the Dynamic Proxy is trying to set the property for a Primary Key that is of type decimal. This is the same error case I have. I am able to reproduce the problem with a simple Gridview and a database consisting of one table.

I am using the standard POCO templates to generate the Context and Proxies.

A workaround would be to change the primary key to an int if this is possible in your environment. It looks like a bug in the framework.