Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error on MiniProfilerEF6.Initialize() c#?

I'm using miniprofiler in MVC project on App_Start() method I invoke

  MiniProfilerEF6.Initialize()

and I get the error :

     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 http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
like image 521
luka Avatar asked Jan 05 '15 09:01

luka


2 Answers

try to add MiniProfilerEF6.Initialize() in application_start function of your Global.asax and make sure it is the first line there.

 protected void Application_Start()
            {          
                  StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize();

    }
like image 126
Emil Avatar answered Sep 18 '22 23:09

Emil


If you have any PreApplicationStartMethod's any where in the project, then make sure you move your MiniProfilerEF6.Initialize() from Global.asax to that class Start method

In my case I use static StructuremapMvc class to setup Ioc, and have

so have

    [assembly: PreApplicationStartMethod(typeof(StructuremapMvc), "Start")]
    public static class StructuremapMvc {
       public static void Start() {
                MiniProfilerEF6.Initialize();
...
...

this fixed for me.

like image 30
pjobs Avatar answered Sep 19 '22 23:09

pjobs