16

I have published my WCF project onto a server, i have also published an MVC application onto the same box which consumes the WCF services.

When trying login on my MVC application, this uses a wcf service, but i get this exception on the browser,

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.

This is an entity framework exception, but i assume since my project already references EF in the dev environment, after deploying the service project, the DLLs should contain the EF reference also but I am not sure why I am getting this error.

I can see this message because I turned on the includeExceptionDetailInFaults="True"

floormind
  • 1,868
  • 5
  • 31
  • 85
  • 1
    installed from NuGet Package Manager cause not correctly installed in the project. try again PM> Install-Package EntityFramework – Nazmul Hasan May 16 '16 at 18:20
  • 1
    As i mentioned, this is not on my local machine, this is on my server where I dont have visual studio installed. This is a published application throwing this error, it works fine on my local machine. @NazmulHasan – floormind May 16 '16 at 18:25
  • Delete the bin folder and clean/rebuild your solution, as I've suggested in [my answer to another similar question](https://stackoverflow.com/a/48541380/1639385). – Ulysses Alves Jan 31 '18 at 11:49
  • Related post - [Entity Framework Provider type could not be loaded?](https://stackoverflow.com/q/14033193/465053) – RBT Jul 30 '21 at 07:37

5 Answers5

18

@FranciscoGoldenstein saying ! You don't need to install Entity Framework in your Console application or whatever, you just need to add a reference to the assembly EntityFramework.SqlServer.dll. You can copy this assembly from the Class Library project that uses Entity Framework to a LIB folder and add a reference to it.

In summary:

  • Class Library application:
    • Install Entity Framework
    • Write your data layer code
    • app.config file has all the configuration related to Entity Framework except for the connection string.
  • Create a Console, web or desktop application:
    • Add a reference to the first project.
    • Add a reference to EntityFramework.SqlServer.dll.
    • app.config/web.config has the connection string (remember that the name of the configuration entry has to be the same as the name of the DbContext class.

it is work for me ! I hope it helps.

also try this link Entity Framework Provider type could not be loaded?

Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
  • you are right, for some reason, the build was not adding that library when i publish it for some reason. – floormind May 16 '16 at 19:41
4

The easiest trick to resolve this issue is to add the following line inside one of the classes in your EF project:

public class Blablabla
{
    private static string __hack = typeof(SqlProviderServices).ToString();

    // other class members as they were before.
}

This will force the build process to copy EntityFramework.SqlServer.dll to the \bin folder of any project that has references to the EF project.

No need to install EF nuget package or make an explicit reference to EntityFramework.SqlServer.dll in any downstream project.

Tohid
  • 6,175
  • 7
  • 51
  • 80
3

Uninstall Entity Framework nuget and just reinstall, worked for me.

Moji
  • 5,720
  • 2
  • 38
  • 39
1

I also had a similar problem

My problem was solved by doing the following:

enter image description here

enter image description here

BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34
0

Maybe is something silly, but for future reference:

In my case I was working with Unit Testing. I added the configuration to the app.config, but never install the Entity Framework to the Unit Test Project.
After installed, so far so good.

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116