Sunday, May 1, 2016

.NET 4.0 DataAnnotations GAC/EntityFramework conflict

Leave a Comment

I'm trying to build an ASP.NET web site for Microsoft .NET 4.0 using Entity Framework 6. The website is explicitly targetting .NET 4.0 in web.config:

<compilation debug="true" targetFramework="4.0">

, IIS Express' application pool in applicationhost.config also targets .NET 4.0:

<add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />

When the site is launched, a number of CS0433 compiler errors is shown, ones like below:

error CS0433: The type "System.ComponentModel.DataAnnotations.Schema.TableAttribute" exists in both "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" and "c:\Users\%username%\AppData\Local\Temp\Temporary ASP.NET Files\vs\e798ee36\2b3f5a24\assembly\dl3\fd34a92a\0052703a_0990d101\EntityFramework.DLL"

As far as I remember, there should be no System.ComponentModel.DataAnnotations assembly in .NET 4.0, or at the very least it shouldn't contain classes like TableAttribute, KeyAttribute etc. The only lead I have is the bottom line of error page, which says

Microsoft .NET Framework, version:4.0.30319; ASP.NET, version:4.6.1055.0 

however, I don't know how to change specifically ASP.NET version for a website (of course, if that's the problem's source).

4 Answers

Answers 1

Have you tried setting the compilation batch to false?

<compilation debug="false" batch="false"> 

Answers 2

Hey Can you check your project.Please check there should not be two model with same properties.Model can also be entity framework class model

Answers 3

Check if all NuGet packages for your project are updated or if there are any installed that you don't want.

Answers 4

I'm assuming you've got code in your App_Code folder (likely your Entity Framework classes at the least?).

Now you could move your code out of there, and precompile everything so that you deploy the website assembly and not any source files.

Otherwise, you really need to look at your projects and ensure that nothing is referencing System.ComponentModel.DataAnnotations.

Also, check any web.config in the project at the root, or in the App_Code folder(s) and make sure there is no

<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 

under system.web/compilation/assemblies. If there isn't, you could even try putting in

<remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 

e.g.:

<compilation>     <assemblies>         <remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />     </assemblies> </compilation> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment