3

I have a C# project with EF 6, and .NET 4.6.1. When I try to execute Enable-Migrations or Update-Database in Package Manager Console, I receive the following error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.SqlServer.SqlProviderServices' threw an exception. ---> System.TypeLoadException: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not have an implementation.

Searching in several places, almost the problem is:

Your EF version and Project Version is not Equal. your Entity Framework is ver 6 of .Net 4 but your project use .net 4.5 Project by .net version 4.5 must use EF for .Net4.5

But my project is using .NET 4.6.1, and I believe that EF is using too.

This is my packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net461" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net461" />
  <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
  <package id="Owin" version="1.0" targetFramework="net461" />
</packages>

I already tried to reinstall all packages (Update-Package -Reinstall) and removed all nuget packages and reinstalled manually

Equalsk
  • 7,954
  • 2
  • 41
  • 67
Roberto Correia
  • 1,696
  • 5
  • 20
  • 36
  • Check your `web.config` and make sure that the referenced .net framework version matches the one you have configured for your project. – Igor Dec 19 '16 at 13:55
  • my project don't have a web.config (it's a class library for custom login on SSRS)! but on `App.config`, there this: ``, and when I execute `Update-Package`, the following message appear: `Attempting to gather dependency information for multiple packages with respect to project 'SIVLogin', targeting '.NETFramework,Version=v4.6.1'` – Roberto Correia Dec 19 '16 at 13:59

1 Answers1

-1

I tried cleaning the NuGET cache, delete the entire .vs subfolder, reinstalled every single package and none worked.

Then, I started a new project on a different folder, and copied every single from the old project to the new project (except .config, .csproj and .sln files). Then, when I build the project, and execute Enable-Migrations and Update-Database, everything worked correctly.

This worked for me, not the best solution, but worked!

Roberto Correia
  • 1,696
  • 5
  • 20
  • 36