This project is read-only.


[Investigate EF6] EF6 RC1 usage in the context of unit tests


While creating a performance suite I came across an issue with EF6 where I was getting

"The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded" under some circustances.

The test in question queries a Code-First EF database to retrieve some test data on the ClassInitialize method. When I ran this test using the VS test runner and the local built in controller, everything was OK.

When I ran the same test, using the Resharper test runner, I would get the could not be loaded exception. But this is just a minor tooling issue.

However, when I try to run the same test using a test controller that is using test agents, I get the could not load exception again, so in the context of a Load test, that test wouldn't run.

When I downgraded to EF5, everything ran as expected, even Resharper test runner firing up the test ran fine.

file attachments

Closed Aug 27, 2013 at 6:47 PM by ajcvickers


ajcvickers wrote Aug 23, 2013 at 5:42 PM

@djfr Could you provide the full stack trace of the exception? Also, if you can create a project that repro's this that would be great. If not, can you provide as much code as possible that shows how and where you are using EF when it causes a problem?


djfr wrote Aug 26, 2013 at 10:22 AM

Attached is an example project.

[WORKS] Running the test with the VS test runner.
[FAILS] Running the test with the R# test runner'.
[FAILS] Running the test with the VS test runner using the test settings file setup for remote execution (you will have to point to a test controller on your development environment).

When it fails it throws:
Class Initialization method EFProviders.Problem.UnitTest.TestInitialize threw exception. System.InvalidOperationException: 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 for more information..


npnelson wrote Aug 27, 2013 at 3:06 PM

I have encountered a similar error under similar circumstances. I tried to create a repro by cutting my production code down. During that process, the error went away. I'll do more work on a repro if you need me to, but you might already have enough to work with. I've attached a screen shot showing the stack trace.

I am running:

1) Windows 8.1 Preview
2) Visual Studio 2013 Preview
3) EF6 RC

Also note that if you take djfr's sample and don't specify a test settings file and run with the default Visual Studio 2013 Test runner, the test will fail. This is consistent with my case, although in my case I use a runsettings file. With the runsettings set, the tests run fine, without, they can fail.

The runsettings file I use is from:

Let me know if there is anything else I can do to help,


P.S. I just wanted to say thanks for making EF6 open source and publishing your design meeting notes, issues, etc. It's given me a lot of useful insight and has made me a better programmer. Thanks for all your hard work.

ajcvickers wrote Aug 27, 2013 at 6:46 PM

I was unable to repro this with the VS test runner using remote tests. However, I was able to repro using the ReSharper runner. In this case the issue is that either the runner and/or MSTest is not deploying the EntityFramework.SqlServer provider assembly to the location where the tests are run. This appears to be because neither the app assembly or the test assembly make use of any types in the provider assembly. However, the provider assembly is referenced in the project and so MSTest and/or the runner should be deploying the provider assembly. Given the stack trace from @npnelson (thanks!) it looks like the MSTest has the same problem in the VSRunner when this repros. (Just FYI: a similar error would also be generated if the app.config is not deployed correctly.)

Given that this is a bug in the way MSTest and/or the runners are deploying assemblies I am going to close this issue as external. To work around the issue you can make your test assembly directly reference the provider assembly by adding some line like this anywhere in the test assembly:
var _ = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
I also remember that MSTest has a way of specifying additional assemblies to be deployed when running tests, so this may also help.


djfr wrote Aug 28, 2013 at 9:58 AM

Thanks for the quick reply.

Just wanted to confirm that adding a code reference to something on the providers assembly fixed the problem both for R# and for remote execution under test agents.

For the remote execution scenario, like you mentioned, adding EntityFramework.SqlServer assembly to the deployment options in the testsettings file will also fix the problem.

Thanks for all the work in making EF great and open source! I have learned a lot just by looking around in your codebase.

kszczesny wrote Oct 17, 2013 at 12:49 PM

I've had the same issue with version 6.0.1. Adding a code reference helped.

martincostello wrote Oct 17, 2013 at 7:24 PM

I've just run into this with 6.0.1 when using the MSTest under TFS 2012. I'd rather not add an unnecessary code-reference to force the DLL to copy, so I'm going down the Deployment Item route.

It's not ideal though, as if I update to a newer version of EF (e.g. 6.0.2) or change the target Framework (I'm currently on 4.0), I will need to update this as well.

haldiggs wrote Aug 6, 2014 at 5:36 PM

whew... just had this happen in my Visual Studio 2013 environment. Using MSTEST and Entity Framework 6.1.

Thanks Arthur for the variable idea

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

works like a charm.