WebActivator icon indicating copy to clipboard operation
WebActivator copied to clipboard

WebActivator methods are running twice

Open deap82 opened this issue 11 years ago • 3 comments

Hi! We're using the PostApplicationStartMethod in a rather large Web Application project and all of a sudden it seems that the methods are called twice (or even multiple times, not sure). It does not happen when I run the site locally, it happens only on our test server which is a Windows 2008 R2 that runs the site on IIS 6.1.

Does anyone have any input on why this might happen?

deap82 avatar Jan 08 '14 16:01 deap82

Hmmm, not sure. It's probably not well tested on IIS6. Can you try to get a stack of the various calls? That might give some clues. I would also suggest isolating by trying it with a trivial test app instead of your big one.

davidebbo avatar Jan 08 '14 17:01 davidebbo

Here is a stack trace:

[ArgumentException: A route named 'CourseCatalog' is already in the route collection. Route names must be unique.
Parameter name: name]
   System.Web.Routing.RouteCollection.Add(String name, RouteBase item) +437
   System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +357
   Mira.CE.UI.App_Start.RouteConfig.Execute() in d:\ProjectsBuild\NE5_AARHUS\Mira.CE.UI\App_Start\RouteConfig.cs:45

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +537
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +341
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +854
   WebActivatorEx.ActivationManager.RunPostStartMethods() +40
   WebActivatorEx.StartMethodCallingModule.Init(HttpApplication context) +159
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +1493
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +389
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +416

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +646
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +669

And error message:
A route named 'CourseCatalog' is already in the route collection. Route names must be unique.
Parameter name: name
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: A route named 'CourseCatalog' is already in the route collection. Route names must be unique.
Parameter name: name

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

So in this case we use it to register routes in an mvc application. The strange thing is that I tried to wrap the route registration in a try/catch (just to get it running) and I still get the error... And this has worked without errors for several months...

deap82 avatar Jan 08 '14 17:01 deap82

If you look at the code for StartMethodCallingModule.Init (which is on your stack), it has logic to make sure the call is only made once. It may be interesting to get the stack of all the different calls you're getting to see if they all come from the same place.

davidebbo avatar Jan 08 '14 20:01 davidebbo