如何在System.Web.Compilation.BuildManager内调试事件?它在IIS / ASP.net生命周期的哪个阶段被调用?
问题是我有一些代码使用PreApplicationStartMethodAttribute但似乎没有触发。所以我试图找出将调试器附加到它的最佳方法。
这里有更多关于更大问题的细节 Why does PreApplicationStartMethodAttribute() not work in SharePoint 2013?但是我把它打破了 尝试取得一些进展的小问题。
到目前为止,我只能识别以下调用堆栈......
BuildManager.CallPreStartInitMethods - > BuildManager。GetPreStartInitMethodsFromAssemblyCollection()
答案 0 :(得分:1)
我正在处理类似的(或者可能是相同的问题)并且可以为您提供完整的堆栈跟踪。您可以自己生成它,只需创建一个简单的小型MVC应用程序,并在使用PreApplicationStartMethodAttribute调用的方法中抛出异常。你会得到:
[ApplicationException: joe was here]
MvcApplication2.JoeStart.Start() in c:\Users\Joe\Documents\Visual Studio 2012\Projects\MvcApplication2\MvcApplication2\JoeStart.cs:18
[InvalidOperationException: The pre-application start initialization method Start on type MvcApplication2.JoeStart threw an exception with the following error message: joe was here.]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): The pre-application start initialization method Start on type MvcApplication2.JoeStart threw an exception with the following error message: joe was here.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254