Error on MiniProfilerEF6.Initialize () C #?

I use miniprofiler in the MVC project for the App_Start () method, which I call

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. 
+5
source share
2 answers

try adding MiniProfilerEF6.Initialize () to the application_start function of your Global.asax and make sure this is the first line.

  protected void Application_Start() { StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize(); } 
+1
source

If you have PreApplicationStartMethod anywhere in the project, make sure you move MiniProfilerEF6.Initialize() from Global.asax to this class. Launch method

In my case, I use the static StructuremapMvc class to configure Ioc and

so that

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

This is fixed for me.

0
source

Source: https://habr.com/ru/post/1210388/


All Articles