Application Update for .Net Framework 4.5 - Cannot Get Correct DataAnnotations Build

My new build for the application that I updated fails. Update for .Net Framework 4.0 to 4.5 and EF to version 6. Error message:

Models \ Mapping \ vw_EmployeesAndJobTitlesMap.cs (47): type name "DatabaseGeneratedOption" not found. This type was redirected to the assembly 'System.ComponentModel.DataAnnotations, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35'. Consider adding a link to this assembly.

In the log I get the following:

Built $ / SCD4 / SCD4.Model / SCD4.Model.csproj.metaproj by default target.

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

00:01 Built-in $ / SCD4 / SCD4.Model / SCD4.Model.csproj for default purposes. C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.Common.targets (847): reference assemblies for the ".NETFramework, Version = v4.5" framework were not found. To solve this problem, install the SDK or Targeting Pack for this version of the framework or reconfigure the application to the version of the framework for which you have an SDK or targeting package. Please note that assemblies will be allowed from the Global Cache (GAC) and will be used instead of control assemblies. Therefore, your assembly may be incorrect designed for the structure that you plan to use. c: \ Builds \ 1 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ packages \ EntityFramework.6.0.2 \ Lib et45 \ EntityFramework.dll: A reference to the type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' states that 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 cannot be found c: \ Builds \ 1 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ packages \ EntityFramework.6.0.2 \ Lib et45 \ EntityFramework.dll: A reference to the type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims to be 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 cannot be found c: \ Builds \ 1 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ n chum \ EntityFramework.6.0.2 \ Lib et45 \ EntityFramework.dll: A reference to the type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' claims to be 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 cannot be found c: \ Builds \ 1 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ packages \ EntityFramework .6.0.2 \ Lib et45 \ EntityFramework.dll: A reference to the type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' states that 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 cannot be found c: \ Builds \ 1 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ packages \ EntityFramework.6.0. 2 \ Lib et45 \ EntityFramewo rk.dll: A reference to the type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' states that 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 could not be found Models \ Mapping \ vw_EmployeesAndJobTitlesMap.cs (24): type name "DatabaseGeneratedOption" was not found. This type was redirected to the assembly 'System.ComponentModel.DataAnnotations, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35'. Consider adding a link to this assembly.

When I click the link in the log, this particular line seems to be the problem:

using System.ComponentModel.DataAnnotations.Schema; 

EF is version 6. Error messages say 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 see him, he exists.


My log file is as follows:

The assembly began on 02/20/2014 14:38:54. The project "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ SCD4 \ SCD4.sln" on node 1 (default goals). ValidateSolutionConfiguration: Configure the Debug | Any Processor building configuration. The project "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ SCD4 \ SCD4.sln" (1) builds "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ SCD4 \ SCD4 \ SCD4.csproj.metaproj "(2) on node 1 (default targets). The project "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ SCD4 \ SCD4 \ SCD4.csproj.metaproj" (2) builds "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ SCD4.Repository \ SCD4.Repository.csproj.metaproj "(3) on node 1 (default targets). The project "C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ MVC4 \ sCD4 \ SCD4.Repository \ SCD4.Repository.csproj.metaproj" (3) builds "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: reference assemblies for the ".NETFramework, Version = v4.5" framework were not found. To solve this problem, install the SDK or Targeting Pack for this version of the framework or reconfigure the application to the version of the framework for which you have an SDK or targeting package. Please note that assemblies will be allowed from the Global Cache (GAC) and will be used instead of control assemblies. Therefore, your assembly may be incorrect designed for the structure that you plan to use. [C: \ Builds \ 2 \ SCD4 \ SCD4 - Test \ Sources \ StandardClassLibrary \ StandardClassLibrary \ StandardClassLibrary.csproj] PrepareForBuild: creating the directory "obj \ Debug \". GenerateTargetFrameworkMonikerAttribute: skip the target "GenerateTargetFrameworkMonikerAttribute" because all output files are relevant 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__b03f5f7a1150 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.D ata.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 Models FileSystem.cs \ JqueryDataTableParamModel.cs SessionObjects.cs StandardConstants.cs Dynamic.cs UserMembership .cs Properties OperationStatus.cs \ AssemblyInfo.cs RepositoryBase.cs "C: \ Users \ TF SBuildAgent \ AppData \ Local \ Temp.NETFramework, Version = v4.5.AssemblyAttributes.cs "


How to fix it?

+6
source share
2 answers

You can solve this problem by adding a link to the specified DLL.

In Visual Studio (2010/2012/2013), right-click on the links for your project and select "Add Link".

Then select the Assemblies tab and go to System.ComponentModel.DataAnnotations and check this box. Then select “OK” and the link will be added.

Now your project should build correctly if you also have using System.ComponentModel.DataAnnotations; in your cs file.

+3
source

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

It seems that even if you are targeting the .NET Framework 4.5, you still have a link to EntityFramework.dll v4.4.0.0 somewhere.

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

At run time, the new EntityFramework.dll (5.0.0.0) is used, and it looks for attributes from the System.ComponentModel.DataAnnotations assembly - those cannot be found, since you have tags from EF.dll 4.4.0.0, and therefore it looks like this: attributes are ignored.

+3
source

All Articles