error on MiniProfilerEF6.Initialize() c#?

2019-06-22 13:51发布

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.

2条回答
Bombasti
2楼-- · 2019-06-22 14:30

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.

查看更多
女痞
3楼-- · 2019-06-22 14:43

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();

    }
查看更多
登录 后发表回答