I have an existing MVC3 application on my production server that has been out there for a long time and hasn’t really changed. Recently, we started putting MVC4 applications on our server, so we installed ASP.NET 4.5 on that server. The old MVC3 application hadn’t been used in a while (and of course we didn’t test this one when we upgraded!), but after the upgrade, it began getting this error:
System.Diagnostics.Contracts.ContractException: Assertion failed: primitiveType != null at System.Runtime.CompilerServices.ContractHelper.TriggerFailureImplementation(ContractFailureKind kind, String displayMessage, String userMessage, String conditionText, Exception innerException) at System.Data.Entity.ModelConfiguration.Utilities.RuntimeFailureMethods.ReportFailure(ContractFailureKind contractFailureKind, String userMessage, String conditionText, Exception innerException) at System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions..cctor()
I fired up VS2010 and went back into the project to see if I could replicate this error on my local machine. Of course, the first thing I had to do was to update the project file to fix the references to System.Web.WebPages (see https://blog.luppes.com/2012/03/01/mvc4-beta-side-by-side-with-mvc3/). Once that was fixed, when I fired up the app, I got the same error, and it was breaking on the line that created my dbContext.
After a little experimenting, I updated the Entity Framework to the latest version, and everything was fixed. Nothing else changed, but now it works fine. Not sure of the exact details, but it would appear some of the older versions of Entity Framework are not compatible with ASP.NET 4.5. Very strange…
Written by Lyle Luppes.