.NET 4.0 DataAnnotations GAC / EntityFramework Conflict

I am trying to create an ASP.NET website for Microsoft.NET 4.0 using Entity Framework 6. The website is explicitly targeting .NET 4.0 in web.config :

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

The IIS Express applicationhost.config pool in applicationhost.config also for .NET 4.0:

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

When the site is started, several CS0433 compiler errors are CS0433 , for example:

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, in .NET 4.0 there should be no System.ComponentModel.DataAnnotations assembly, or at least it should not contain classes such as TableAttribute , KeyAttribute , etc. The only thing I have is the bottom line of the error page, which says

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

however, I do not know how to change the specific version of ASP.NET for the website (of course, if this is the source of the problem).

+6
source share
4 answers

Have you tried setting the compilation package to false?

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

Hey. Can you check your project. Please check that there should not be two models with the same properties. The model can also be a model of the Framework entity class.

0
source

Check if all NuGet packages are updated for your project or if any installed ones that you do not want are installed.

0
source

I assume that you have the code in your App_Code folder (probably your Entity Framework classes at least?).

Now you can move your code and recompile everything so that you deploy the assembly of the website, and not any source files.

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

Also, check any web.config in the project in the root directory or in the App_Code folder and make sure no

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

under system.web / compilation / assembly. If this does not happen, you can even try inserting

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

eg:.

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

You can also verify that it works with an earlier version of ASP.NET so that it builds a version of the DataAnnotations assembly that does not have a Schema attribute (as version 4.5+ does):

 <configuration> <system.web> <httpRuntime targetFramework="4.0" /> </system.web> </configuration> 
0
source

All Articles