The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' could not be loaded

You don't need to Install EF6 NuGet Package in client application, The error is not related to client application because the client application connects to WCF Services and don't know even if a database or data access layer exists.

This error is related to lack of EntityFramework.SqlServer.dll in bin folder of your service library and/or host project.

Option 1

The most simple way is to install EF6 using NuGet Package Manager in your WCF Host project too, and if it has been installed before, try uninstalling and installing it again. This way EntityFramework.SqlServer.dll to output directories.

Please note that this way is somehow against n-layered rules because this your libraries above data access layer are dependent to EF6 which is not so good.

Option 2

As a workaround to copy EntityFramework.SqlServer.dll in output directories, make sure Copy Local of this dll is set to true and then put this code in your DbContext constructor:

var ensureDllIsCopied = System.Data.Entity.SqlServer.SqlProviderServices.Instance; 

It ensures EntityFramework.SqlServer.dll is copied to output directory of consumers of data access project. This is a workaround.

Using this way you don't have any dependency to EF in your layers above data access layer.


I fixed this by installing entity framework in the WCF host site.

That worked.


There's an issue which a number of people have reported when using EF 6 with Code First around the EntityFramework.SqlServer provider (or another provider they are using) not being copied locally. This leads to the following error:

System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

This only occurs when the EntityFramework NuGet package is not installed in the start-up project (i.e. it is only installed in a class library etc.)

This issue isn't specific to Entity Framework, but is a side effect of how MSBuild works out which assemblies need to be deployed. The issue occurs because there is no code in the application that explicitly references types in EntityFramework.SqlServer.dll (or relevant provider assembly) since EF will load the assembly at runtime based on info in the App/Web.config file. As a result, MSBuild does not detect that the assembly is needed and will not copy it to the output directory