Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading application for .Net Framework 4.5 - cannot get correct DataAnnotations assembly

My new build for the application I have upgraded fails. The upgrade is for .Net Framework 4.0 to 4.5 and EF to version 6. The error message is;

Models\Mapping\vw_EmployeesAndJobTitlesMap.cs (47): The type name 'DatabaseGeneratedOption' could not be found. This type has been forwarded to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.

In the log I get the following;

Built $/SCD4/SCD4.Model/SCD4.Model.csproj.metaproj for default targets.

00:00 Built $/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary.csproj for default targets.

00:01 Built $/SCD4/SCD4.Model/SCD4.Model.csproj for default targets. c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (847): The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found c:\Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib et45\EntityFramework.dll: Reference to type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims it is defined in 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll', but it could not be found Models\Mapping\vw_EmployeesAndJobTitlesMap.cs (24): The type name 'DatabaseGeneratedOption' could not be found. This type has been forwarded to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.

When I click on the link in the log, it is this line that seems to be the problem;

using System.ComponentModel.DataAnnotations.Schema;

EF is version 6. The error messages says that c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll does not exist, but when I look it does exist.


My log file looks like;

Build started 20/02/2014 14:38:54. Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln" on node 1 (default targets). ValidateSolutionConfiguration: Building solution configuration "Debug|Any CPU". Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln" (1) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj" (2) on node 1 (default targets). Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4\SCD4.csproj.metaproj" (2) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj" (3) on node 1 (default targets). Project "C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.Repository\SCD4.Repository.csproj.metaproj" (3) is building "C:\Builds\2\SCD4\SCD4 - Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj" (4) on node 1 (default targets). c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(847,9): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\Builds\2\SCD4\SCD4 - Test\Sources\StandardClassLibrary\StandardClassLibrary\StandardClassLibrary.csproj] PrepareForBuild: Creating directory "obj\Debug\". GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. CoreCompile:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib\net40\EntityFramework.dll" /reference:"C:\Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib\net40\EntityFramework.SqlServer.dll" /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll /reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll /reference:"c:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll" /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll /reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\StandardClassLibrary.dll /target:library EmailMessage.cs FileSystem.cs Models\JqueryDataTableParamModel.cs SessionObjects.cs StandardConstants.cs Dynamic.cs UserMembership.cs OperationStatus.cs Properties\AssemblyInfo.cs RepositoryBase.cs "C:\Users\TFSBuildAgent\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"


How do I fix this?

like image 300
arame3333 Avatar asked Feb 17 '14 16:02

arame3333


2 Answers

You can resolve this by adding a reference to the DLL that it mentioned.

In Visual Studio (2010/2012/2013), right click on the references of your project and select 'Add Reference'.

Then select the Assemblies tab and navigate to System.ComponentModel.DataAnnotations and tick the check box. Then select OK and the reference will be added.

Your project should now build correctly as long as you also have a using System.ComponentModel.DataAnnotations; in your cs file.

like image 66
Rob Aston Avatar answered Oct 13 '22 18:10

Rob Aston


In .NET Framework 4.5, EF annotations were moved from EF.dll to System.ComponentModel.Annotations assembly.

It seems that even though you target .NET Framework 4.5, you still have a reference to EntityFramework.dll v4.4.0.0 somewhere.

As a result your classes are compiled with attributes from the 4.4.0.0 assembly.

At runtime the newer EntityFramework.dll (5.0.0.0) is being used and it looks for attributes from System.ComponentModel.DataAnnotations assembly - Those cannot be found since you have the ones from EF.dll 4.4.0.0 and therefore it looks like attributes are being ignored.

like image 33
Yair Nevet Avatar answered Oct 13 '22 20:10

Yair Nevet