error on MiniProfilerEF6.Initialize() c#?

▼魔方 西西 提交于 2019-12-23 10:08:38

问题


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.

回答1:


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

    }



回答2:


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.



来源:https://stackoverflow.com/questions/27776510/error-on-miniprofileref6-initialize-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!