Gary O. Stenstrom Gary O. Stenstrom - 8 months ago 55
ASP.NET (C#) Question

Type definition exists in two libraries

I am building an ASP.NET Web Forms web site using .NET 4.5.

The error ...

The type 'System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute' exists in both 'f:\Projects\web sites\RC1Iteration05\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'

I have tried to alias the libraries using ...

csc /r:EF_DataAnnotations="f:\Projects\web sites\RC1Iteration05\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll" /r:CM_DataAnnotations="c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll"

but this only resulted in "No Source File specified" which is equally confusing since the source files were specified as directed (here & here).

I did notice that the error was referencing the EF dll in the net40 folder rather than the net45 folder. I figure if I used the net45 version the problem would resolve itself, however I do not know how to change that reference. I changed the "targetFramework" attribute to the EntityFramework package in the packages.config file, but that did not make any difference.

I am a bit stuck since both of the solutions did not seem to do anything.

I looked around and found a number of posts here where folks have dealt with similar issues but have received no responses. I am hoping that there is someone out there who can help!




As you noticed, you're using the .Net 4.0 version of Entity Framework on .Net 4.5.
That won't work.

Re-install EF from NuGet and it should work fine.