ASP.NET: This method cannot be called during the application's pre-start initialization stage

前端 未结 5 1294
旧巷少年郎
旧巷少年郎 2020-11-27 11:02

I\'m trying to get an ASP.NET MVC 3 site running on IIS 6.0.

Currently when I request a page from the server it gives the following error:

Pa

5条回答
  •  醉梦人生
    2020-11-27 11:28

    This is caused by any of a number of Reflection calls being made too early in an Application. It just so happens the Web.Config suggestions in other answers prevented one such Reflection call from being made. In my case however:

    I'm using Entity Framework, and ran update-database. I got:

    This method cannot be called during the application's pre-start initialization phase.

    As it turns out we had code that used a library which was recently modified to get all code in all namespaces/projects. Specifically, it called:

    System.Web.Compilation.BuildManager.GetReferencedAssemblies()
    

    Kaboom. That caused this obscure error. EF Migrations run in a weirdo zone where the application is half running and half not, meaning the above method can never be called by any code Migrations would call on.

提交回复
热议问题