'Enable-Migrations' fails after upgrading to .NET 4.5 and EF 5

假装没事ソ 提交于 2019-11-29 13:29:55

I just had the same problem and found your question while searching for a solution.

I got it working. The problem, for me, was that I initially targeted the .NET 4.0 framework when I added the EF 5 via NuGet. Changing the target framework and then reinstalling EF 5 via NuGet, fixed it. It's also possible (see comments) that just reinstalling EF 5 via NuGet is the solution for you.

I had the following line in the App.config file, notice Version=4.4.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>

So what I did was set the target framework to 4.5 inside the solution configuration and set the supported runtime to 4.5 too (inside the app config).

Old:

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

New:

  <startup>
    <supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />
  </startup>

After that change, I removed EF 5.0 via NuGet and added it again. It gave me the following configSection as result, notice Version=5.0.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>

After that change, it worked.

I was also faced the same problem, but after a day I suddenly get attention to a file called packages.config in the ASP MVC 4 project folder. So, here i get

 <package id="EntityFramework" version="6.0.2" targetFramework="net45" />

I changed the version number to my appropriate number i.e. for me i used EF ver 5.0.0. After I change the version, everything is fine now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!