Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebActivator.PreApplicationStartMethod does not work

[assembly:  WebActivator.PreApplicationStartMethod(typeof(MyApp.App_Start.StructureMapMvc), "Start")]

namespace MyApp.App_Start
{
    public static class StructureMapMvc
    {
        public static void Start()
        {
            var container = IoC.Initialize();
            DependencyResolver.SetResolver(new SmDependencyResolver(container));
        }
    }
}

Here is my code that is supposed to run before Application_start in global.asax. I was upgrading my web project from mvc 3 to mvc 4. So, In that process, I made a mistake in namespace. This was working before i corrected my namespace. It no longer works now. I reset iis/flushed dns/ rebuilt solution/removed the temporary .net files in C:\Windows\Microsoft.NET\Framework64\versionxxxxxx...\Temporary ASP.NET Files\root. Nothing worked. Am i missing something here? The Initialize() method has all my structure map stuff dependency resolution stuff. So, I can't move forward without figuring this out. Tried to diagnose the problem for so many hours and i need help.

like image 534
Maneeshpal Avatar asked Jan 02 '13 00:01

Maneeshpal


2 Answers

My experience is that WebActivator will not work if your project settings (in .csproj.user or .vbproj.user) have the setting <StartAction>NoStartPage</StartAction> the fix is to set it to <StartAction>CurrentPage</StartAction> and it should then work next time you debug.

Also since it's in a .user file (which are typically not included in svn) it is difficult to determine why it works on some dev environments but not others.

like image 195
Seph Avatar answered Nov 19 '22 06:11

Seph


If your code is in a Web Site Project (ie, under the App_Code folder) you cannot use PreApplicationStartupMethod! You can use PostApplicationStartupMethod instead. The "Pre" method executes before global.asax *Application_Start* runs, while "Post" executes after.

I wasted a good hour or two before I figured this out, so hopefully this will help someone else avoid that!

like image 32
kenchilada Avatar answered Nov 19 '22 07:11

kenchilada