Exception using EF6

Hi,
I got MiniProfiler.EF6 3.0.10-beta4 package and at moment to run the app. I got this exception:

“An exception of type ‘System.InvalidOperationException’ occurred in EntityFramework.dll but was not handled in user code. Additional information: 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.”

As extra information I got the package MiniProfiler.MVC4 3.0.10-beta1 what is working fine.
Any idea?

Can you please make sure that the MiniProfiler.EF6.Initialize() function is run before any other db access is performed through EF?

Hi
I’m bashing my head with this one. I’ve put the line as the first thing in the App_Start method and I’m still getting the exception. I even tried creating a constructor for the app and initialising it there but still got the exception.

Do you know anything that could be starting up EF prior to Global.asax?

On your Application_Start, you can do this

` MiniProfilerEF6.Initialize();
Database.SetInitializer<Performance.DataModel.PerformanceContext>(null);// Remove this if implementing database migration it gets rid of context has changed exception

`On your application begin request you can put this
if (Request.IsLocal)
{
MiniProfiler.Start();
}

Then on your Application_EndRequest you can do this

MiniProfiler.Stop();