This project has moved and is read-only. For the latest updates, please go here.

Loaded' event handlers can only be added as part of application start

Dec 27, 2013 at 11:55 PM
I've been trying to get Effort working, in a EF6, .NET 4.5, VS2012, database-first project. I've made some progress. I've one unit test that runs, when I run it alone. But when I run it as a part of my whole test suite, it fails with a System.TypeInitializationException:
System.TypeInitializationException: The type initializer for 'Effort.EntityConnectionFactory' threw an exception. ---> System.InvalidOperationException: The Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used. See for more information..
My guess is that the problem is that I have other tests running against EF, that are using Moq to mock-out my DbContext, without using Effort. When I comment out these, my test using Effort succeeds. When I add them back, I get this exception, again.

It looks like what Effort is doing, when it is loading EF, only works if nothing else has loaded EF, before it starts. Any idea how I can get EF to throw away its existing configuration at the start of every test?
Dec 28, 2013 at 2:07 AM

Take a look on this thread for answer.
Marked as answer by tamasflamich on 1/25/2014 at 3:07 PM
Dec 30, 2013 at 3:54 PM

That does seem to have managed it. Thanks.