5

All,

I'm running into trouble deploying an ASP.NET 4.0 web page. The error is

System.InvalidProgramException: Common Language Runtime detected an invalid program

The error occurs on IIS7 on a 64 bit Windows Server box. The same page works on IIS7 on my development box (32bit Windows 7) and in the Visual Studio Development Environment. I'm not aware of any differences in the IIS7 configuration.

I've used PEVerify to validate the dll's in the application's bin directory.

I can reproduce the problem by using an Entity Framework query to populate a DataGrid.DataSource. It is not a particularly heavy query.

Any ideas on what could be causing this? My next step is to try and simply the queries used.

Thanks for any help.

HatAndBeard
  • 1,416
  • 3
  • 18
  • 31

3 Answers3

5

This looks like it's due to a primary key of type decimal(1,0).

HatAndBeard
  • 1,416
  • 3
  • 18
  • 31
  • I had a composed primary key (created by the EF designer) on a view. One of the columns was decimal - BAM, the error :). Removing the decimal column as primary key fixed the issue. Thanks – sirrocco Dec 13 '10 at 12:14
  • 1
    + 1 - I ran into the same problem. I composed a model from a view, and the designer automatically assumed that a bunch of fields (including a decimal) were part of the entity key. After reading this post, I checked the properties on the model and manually removed the incorrect fields from the entity set key. This cleared the problem right up. Thanks! – dotariel Jan 14 '11 at 17:48
  • +1 XSaint32, it had not occurred to me to check if VS had automatically set extra columns as part of the entity key as I *knew* the key was a single column. Gotta love time sink gotchas like this. – Tedford Mar 22 '11 at 15:07
  • The bug was marked as fixed. Have you tried EF 4.1? https://connect.microsoft.com/VisualStudio/feedback/details/620031/invalidprogramexception-using-entityframework-poco-template-table-w-decimal-primary-key – HatAndBeard Mar 30 '11 at 16:53
  • @hat how did you find which table in the EF model had an extra PK? I have several hundred tables - don't want to have to check each of them one by one – JK. Jul 13 '11 at 01:34
1

I think it could be a number of issues. Depending on your Entity Framework model, and how big/complex it is, you might be running into a limit of the JIT compiler. This applies to 2.0, so it might apply to 4.0 as well.

Assuming you don't have any huge methods, did you compile your assembly for Any CPU? If you specified a processor, then a mismatch between 32/64 bits will cause issues. Try rerunning with with Any CPU.

Let me know if that works.

Erick

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Erick T
  • 7,009
  • 9
  • 50
  • 85
  • The data model isn't very large or complex (~25 entities). The CPU is compiled for Any CPU. My understanding from the 2.0 issue is that there was a hot fix to up the local variable limit to 4 million. I assume (hope) that wasn't overlooked when creating 4.0. – HatAndBeard Nov 05 '10 at 19:23
0

I got the same error on a line of code that was bug-free for months. Luckly, I was able to revert my changes to a working state and retrace my steps. It turns out that it was a line of code within the same Task.Run() enclosure that was causing the error. What's scary is that there was nothing wrong with the code: var test = user.objectId.HasValue; but once I remove this line, the error went away.

    public virtual Task<IList<string>> GetRolesAsync(TUser user) {
        if (user == null)
            throw new ArgumentNullException("user");
        return Task.Run(() => {
            var test = user.objectId.HasValue;
            var userRolesQuery = objectManager.buildQueryByFilter<List<security.UserRole>>("user = '{0}'", user.objectId);
            objectManager.buildSubquery<TRole>("role", userRolesQuery);
            var userRoles = objectManager.openByQuery<List<security.UserRole>>(userRolesQuery);
            return (IList<string>)userRoles.Select(userRole => userRole.role.name).ToList();
        });
    }
Bill Heitstuman
  • 979
  • 1
  • 8
  • 23