4

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.

4

2 に答える 2

15

WebApi で OWIN ミドルウェアを使用しているため、次のアセンブリ属性を持つ Startup クラスが必要です [assembly: OwinStartup(typeof(Startup))]

また、WebApi に Swagger インターフェイスを使用し、nuget パッケージを介してインストールしました。インストールにより、次のアセンブリ属性を持つ SwaggerConfig クラスが追加されました [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

WebApi の開始時に、アセンブリ属性がこの例外を引き起こしていました。SwaggerConfig クラスからアセンブリ属性を削除しましたが、すべて正常に動作しています。

于 2016-10-14T20:44:26.223 に答える
5

bin フォルダー内の古いアセンブリであることが判明し、参照されなくなったため、問題が発生しました。

于 2015-06-26T15:48:57.303 に答える