.NET 4.0 DataAnnotations GAC/EntityFramework conflict

.net asp.net entity-framework-6 gac

Question

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).

1
6
12/27/2019 7:27:14 PM

Popular Answer

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>

You can also check to make sure it's running the earlier version of ASP.NET so that it picks up the version of the DataAnnotations assembly that doesn't have the Schema attribute (as the 4.5+ framework version does):

<configuration>
  <system.web>
    <httpRuntime targetFramework="4.0" />
  </system.web>
</configuration>
0
5/10/2016 9:34:11 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow