Elliot Wood
Elliot Wood

Reputation: 964

How do I debug inside the System.Web.Compilation.BuildManager

How do you debug events inside System.Web.Compilation.BuildManager? And in what stage of the IIS/ASP.net lifecycle is it called?

The problem is I have some code that uses the PreApplicationStartMethodAttribute but does not seem to fire. So I am trying to figure out the best way to attach a debugger to it.

There is some more details about the larger problem here Why does PreApplicationStartMethodAttribute() not work in SharePoint 2013? but I have broken it into a smaller problem to try and make some progress.

I've only been able to identify the following call stack so far...

BuildManager.CallPreStartInitMethods -> BuildManager.​GetPreStartInitMethodsFromAssemblyCollection()

Upvotes: 0

Views: 798

Answers (1)

Joe Capka
Joe Capka

Reputation: 562

I'm working on a similar (or perhaps the same issue) and can give you the full stack trace. You can generate it yourself btw, just create a simple small MVC app and throw an exception in the method that you call using the PreApplicationStartMethodAttribute. You will get:

[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

Upvotes: 1

Related Questions