Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MiniProfilerEF6.Initialize()c#上出错?_C#_Mvc Mini Profiler - Fatal编程技术网

MiniProfilerEF6.Initialize()c#上出错?

MiniProfilerEF6.Initialize()c#上出错?,c#,mvc-mini-profiler,C#,Mvc Mini Profiler,我正在调用App_Start()方法的MVC项目中使用miniprofiler MiniProfilerEF6.Initialize() 我得到了一个错误: 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 b

我正在调用App_Start()方法的MVC项目中使用miniprofiler

  MiniProfilerEF6.Initialize()
我得到了一个错误:

     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.

尝试在Global.asax的application_start函数中添加MiniProfilerEF6.Initialize(),并确保它是那里的第一行。

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

    }

如果您在项目中的任何位置有任何
PreApplicationStartMethod
,请确保将
MiniProfilerEF6.Initialize()
Global.asax
移动到该类启动方法

在我的例子中,我使用静态StructuremapMvc类来设置Ioc,并且

我也是

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

这对我来说是固定的。

你应该为你的问题添加更好的标签。我认为c#是不够的。在代码的某个地方,您试图访问数据库,但需要添加这一行
MiniProfilerEF6.Initialize()
在访问数据库之前,它仍然会崩溃。您会遇到什么样的崩溃?已经加载了初始化程序,或者类似的情况。我开始进行更多的调试,似乎在Unity和IUnitOfWork的基础上构建了一些东西,在应用程序启动之前进行初始化