The type 'MaxLengthAttribute' exists in both 'EntityFramework, and 'System.ComponentModel.DataAnnotations - entity-framework

I am doing some spring cleaning on a legacy Web Api 2 project (target 4.5). As part of the the nuget updates, I moved Microsoft.AspNet.WebApi.HelpPage from version 5.0.0 to 5.2.3. Once I do that, I am getting the following message:
Error CS0433 The type 'MaxLengthAttribute' exists in both
'EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' and
'System.ComponentModel.DataAnnotations, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'
It looks like this was a problem a while back when they moved that class from EF to DataAnnotations and the solution was to upgrade EF. Since I have the most recent stable version of EF (5.2.3), I am not sure what else to do. I tried removing System.ComponentModel.DataAnnotations from the using statements, but then it doesn't pick up the EF MaxLengthAttribute. Cleaning and rebuilding the solution also does not work.
Any pointers are appreciated.

Related

System.IO.FileNotFoundException: Could not load assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Getting this Error In Xamarin Form Android Project I am refering Entity framework library int android project. Error as below
Severity Code Description Project File Line Suppression State Error
Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'EntityFramework, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'. Perhaps it doesn't
exist in the Mono for Android profile? File name:
'EntityFramework.dll' at
Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference
reference, ReaderParameters parameters) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection`1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver
resolver) RadLoc.Android C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets
1500
I am stuck here please help me out of this..
Just like #magicandre1981 said. Entity Framework doesn't fit in Xamarin.Android project. You need to use EntityFramework Core.
For a simple jump in and brief introduction, you can refer to Building Android Apps with Entity Framework.
For a windows application with this error:
If your copying the exe to a different folder from /bin/
You also need to include a copy of the application .config file along with the EntityFramework.xml and EntityFramework.SqlServer.xml files.

Nuget.exe fails with "Could not load file or assembly 'System.Net.Http...'

I am trying to run "nuget restore" on a server that does not have a Visual Studio installation. But nuget.exe fails immediately. What else needs to be installed for NuGet to run?
C:\Users\kevin>nuget help
Could not load file or assembly 'System.Net.Http,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
Could not load type
'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. Could not load file or assembly
'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
Had this issue as well. Newer versions of NuGet requires .NET 4.5. installing .NET 4.5.2 resolved the issue for me.

WebMatrix 2 doesn't recognize EntityFramework helper

I just started to work on WebMatrix, I did this tutorial to learn the basic and then I started with this one to get started with Entity Framework on WebMatrix (Note: That tutorial is for WebMatrix 1, but the only thing I see changed was the way you install helpers into your project). The thing is, I installed the Entity Framework helper, but my project doesn't recognize the EntityFramework.dll.
I get this error The type or namespace name 'MaxLength' could not be found (are you missing a using directive or an assembly reference?). But the EntityFramework.dll does appear in my bin folder, what is going on? I don't understand why the reference isn't working.
This is my Web.config file according to the second tutorial and after installing the EntityFramework helper:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /><add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></assemblies></compilation>
</system.web>
<connectionStrings>
<add name="BookContext" connectionString="Data Source=|DataDirectory|Books.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
This is the compiler output link
Am I missing something? Why does the EntityFramework.dll isn't being recognized properly by my project?
UPDATE
I thought the problem was solved when I copied the EntityFramework.dll from a webpage project created in Visual Studio 2012, but even though the errors aren't shown anymore, WebMatrix still doesn't recognize annotations like Table, Column, ForeignKey, InverseProperty, etc.
I really don't understand, a simple database is created but I can't use the EntityFramework annotations to specify all I need for the database. WebMatrix should recognize the EntityFramewor.dll but it is not. I need help in this one because I'm really lost.
The error that you see is the end result of the version of EntityFramework installed on your site.
The EntityFramework 5.0 package installs version 4.4 or 5.0 of the EntityFramework.dll depending on the version of .NET (4.0 or 4.5) that the project is targeting.
In my experience, installing EntityFramework from the NuGet Gallery in WebMatrix always copies version 4.4 of EntityFramework.dll into the bin folder: you can check it looking at Properties --> Details of the EntityFramework.dll file.
The only solution I know is to download EntityFramework v.5.0 using VisualStudio Express or another standalone utility (look at this post: Install Entity Framewok v5 in Webmatrix 2 RC) and simply replace the dll installed by NuGet Gallery in WebMatrix with this one.
UPDATE
Other problems experimented with EntityFramework v.5.0 and WebMatrix are that the type 'System.Data.EntityState' is defined in an assembly that is not referenced and that is needed a using directive for DataAnnotations.Schema.
The first problem is resolved adding the following reference to web.config (look at Could not load file or assembly 'System.Data.Entity):
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
The second problem needs the addition of the directive
using System.ComponentModel.DataAnnotations.Schema;
to the code.
Anyway, in my opinion WebMatrix isn't the right tool for developing a site based on EntityFramework.

Could not load file or assembly 'EntityFramework' after downgrading EF 5.0.0.0 --> 4.3.1.0

After too hastily upgrading to EF 5.0.0.0 RC and being stuck with a .NET 4.5 project that wouldn't deploy to Windows Azure (.NET 4.0 and below), I decided to downgrade to EF 4.3.1.0.
I'm unsure of the best way to perform this type of migration but my strategy is to use "Manage NuGet Packages" identify which projects reference the package, uncheck the package from each project, install the replacement and recheck the correct projects.
Unfortunately, after doing this, my solution produced the titular "FileLoadException".
Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I searched through the solution files particularly packages.config for references to EF 5.0.0.0 RC but could find none.
After failed attempts to find references to EntityFramework in repositories.config and elsewhere, I stumbled upon a reference in Web.config as I was editing it to help with my diagnosis.
The bindingRedirect referenced 5.0.0.0 which was no longer installed and this appeared to be the source of the exception. Honestly, I did not add this reference to Web.config and, after trying to duplicate the error in a separate project, discovered that it is not added by the NuGet package installer so, I don't know why it was there but something added it.
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
I decided to replace this with the equivalent element from a working project. NB the references to 5.0.0.0 are replaced with 4.3.1.0 in the following:
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
This worked!
I then decided to remove the dependentAssembly reference for the EntityFramework in its entirety. It still worked!
I would still be interested in answers to these questions:
What added the dependentAssembly for EntityFramework to my Web.config
Any consequence(s) of removing these references
I'd be interested to learn.
I have this issue, and all I did was make sure that I was referencing the right .Net framework in all the projects then just change the web.config from
From
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
To
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false"/>
All works..
I had the same issue when updating an older project. Here's what I did to resolve it:
Converted all projects to .NET 4.5.
Uninstalled the NuGet package for Entity Framework 5.
Reinstalled the NuGet package for Entity Framework 5.
Cleaned the solution.
Rebuilt the solution.
The projects that used Entity Framework 5 and .NET 4 were installing the Entity Framework dll version 4.4. Once I switched the .NET version to 4.5 on the project, the dll version would be 5.
My problem came from older projects being on .NET 4 and a newer project running .NET 4.5 so there were 2 dll versions of EF in my solution.
Hope this helps someone...
I had a similar issue running unit tests using MSTEST under Jenkins. The fix in my case was to remove "Version=6.0.0.0, " as shown below:
Old:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxx" requirePermission="false" />
New:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Culture=neutral, PublicKeyToken=xxxx" requirePermission="false" />
I had to make this change is several App.config and Web.config files in my multi-project solution.
While Building a Project, if in the project properties it shows that it is build under Target.NET Framework 4.5, update it to 4.6 or 4.6.1. Then the build will be able to locate Entity Framework 6.0 in the Web.config file. This approach solved my problem.
Selecting Target framework from Project Properties
If you used the Visual Studio 2012 ASP.NET Web Forms Application template then you would have gotten that reference. I'm assuming it's the one you would get via Nuget instead of the framework System.Data.Entity reference.
I received the exact same error message. Except that my error message said "Could not load file or assembly 'EntityFramework, Version=6.0.0.0...", because I installed EF 6.1.1. Here's what I did to resolve the problem.
1) I started NuGet Manager Console by clicking on Tools > NuGet Package Manager > Package Manager Console
2) I uninstalled the installed EntityFramework 6.1.1 by typing the following command:
Uninstall-package EntityFramework
3) Once I received confirmation that the package has been uninstalled successfully, I installed the 5.0.0 version by typing the following command:
Install-Package EntityFramework -version 5.0.0
The problem is resolved.
I had similar issue with selenium:
I downgraded my selenium using NuGet and got the same error message. My solution was to remove the newer version lines from the app.config file.
I got same issue. I was getting the System.Data.Entity.Infrastructure; error which is only part of v5.0 or later. Just right click the Reference and select "Manage NuGet Package" . In the Installed Package option , uninstall the Entity FrameWork which is already installed and Install the 5.0 version. It solve the problem. I was trying manually get the System.Data.Entity reference , which was not success.
public Configuration()
{
AutomaticMigrationsEnabled = false;
// register mysql code generator
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}
I find out that connector 6.6.4 will not work with Entity Framework 5 but with Entity Framework 4.3. So to downgrade issue the following commands in the package manager console:
Uninstall-Package EntityFramework
Install-Package EntityFramework -Version 4.3.1
Finally I do Update-Database -Verbose again and voila! The schema and tables are created. Wait for the next version of connector to use it with Entity Framework 5.
I had a similar issue:
On my ASP.NET MVC project, I've added a Sql Server Compact database (sdf) to my App_Data folder. VS added a reference to EntityFramework.dll, version 4.* . The web.config file was updated appropriately with the 4.* configuration.
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
I've added a new project to my solution (a Data Access Layer project). Here I've added an EDMX file. VS added a reference to EntityFramework.dll, version 5.0. The App.config file was updated appropriately with the 5.0 configuration
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
On execution, when reading from the database the app always thrown the exception Could not load file or assembly 'EntityFramework, Version=5.0.0.0 ....
The issue was fixed by removing the EntityFramework.dll v4.0 from my MVC project. I've also updated the web.config file with the correct 5.0 version. Then everything worked as expected.
In your references click on the EntitiyFramework .
Go to properties and set the specific version to False.
It worked for me.

assembly problem asp.net mvc / mvc contrib

I am using the s#arp framework and want to use the latest mvc contrib. This means that I have to use asp.net mvc 2.0. So I refrenced the latest 2.0 dll for mvc 2.0 and the latest mvc contrib dll but still get this error:
Error 1 Assembly 'MvcContrib, Version=2.0.36.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c:\Users\bla\Downloads\MVCContrib.release(2)\MvcContrib.dll Bla.Web.Controllers
I checked the mvc dll in my controller project and it is version 2.0. what else can I do?
Thanks!
Chris
Chris,
I would unload any of the projects that reference System.Web.Mvc and edit them to make sure they are
Pointed to the proper version of System.Web.Mvc at the location in the /lib
Are not pointed to the global version (gac)
Christian,
did you also replace it in your web project? Anywhere 1.0 was referenced, you would need to replace it. In addition, you might need to add an assembly binding redirect from 1.0 to 2.0.