Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebActivatorEx causing ArgumentException on Application Start

I keep getting the following ArgumentException when trying to visit a page after installing the WebActivatorEx nuget package.

Server Error in '/PharmaDotnet/ux' Application.
The type Pharma.Mvc.Startup doesn't have a static method named Configuration
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: The type Pharma.Mvc.Startup doesn't have a static method named Configuration

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.

Stack Trace:


[ArgumentException: The type Pharma.Mvc.Startup doesn't have a static method named Configuration]
   WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +166
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +445
   WebActivatorEx.ActivationManager.Run() +105

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: The type Pharma.Mvc.Startup doesn't have a static method named Configuration.]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12981643
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12981352
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +280
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: The type Pharma.Mvc.Startup doesn't have a static method named Configuration.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12980692
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12820285


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249 

If I remove the WebActivatorEx package everything works again but I need WebActivatorEx in order to use DI.

I can't find anything online to suggest what the issue might be. I've tried creating a Startup class in the Pharma.Mvc namespace with a static method called Configuration which does not appear to fix the issue.

Also, before I installed the package there was no Pharma.Mvc namespace nor was there a Startup class. So I'm really confused as to why this is happening.

I'm targeting the ASP.NET 4.5.1 Framework when I build the application however I have noticed that in the stack trace at the bottom it reads Microsoft .NET 4 Framework Version:4.0.30319 and I'm not sure if this is correct or not.

like image 661
Professor of programming Avatar asked Dec 01 '22 00:12

Professor of programming


2 Answers

I am using OWIN middleware with a WebApi and therefore needed a Startup class with the following assembly attribute [assembly: OwinStartup(typeof(Startup))]

I also use the Swagger interface for the WebApi and installed it via a nuget package. The install added the SwaggerConfig class with the following assembly attribute [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

The assembly attribute was causing this exception when starting the WebApi. I removed the assembly attribute from the SwaggerConfig class and everything is working fine.

like image 78
Ron Mooers Avatar answered Dec 16 '22 09:12

Ron Mooers


It turned out to be an old assembly in the bin folder, which was no longer referenced, causing the issue.

like image 41
Professor of programming Avatar answered Dec 16 '22 09:12

Professor of programming