加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – WebActivatorEx在Application Start上导致ArgumentExcepti

发布时间:2020-12-15 19:39:48 所属栏目:百科 来源:网络整理
导读:在安装WebActivatorEx nuget包后尝试访问页面时,我不断收到以下ArgumentException. Server Error in '/PharmaDotnet/ux' Application.The type Pharma.Mvc.Startup doesn't have a static method named ConfigurationDescription: An unhandled exception oc
在安装WebActivatorEx nuget包后尝试访问页面时,我不断收到以下ArgumentException.

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

如果我删除WebActivatorEx包,一切都会再次运行,但我需要WebActivatorEx才能使用DI.

我在网上找不到任何建议可能是什么问题.我尝试使用名为Configuration的静态方法在Pharma.Mvc命名空间中创建一个Startup类,但似乎无法解决问题.

此外,在我安装软件包之前,没有Pharma.Mvc命名空间,也没有Startup类.所以我真的很困惑为什么会发生这种情况.

我在构建应用程序时瞄准了ASP.NET 4.5.1框架但是我注意到在底部的堆栈跟踪中它读取了Microsoft .NET 4 Framework Version:4.0.30319并且我不确定它是否是是否正确.

解决方法

我正在使用带有WebApi的OWIN中间件,因此需要具有以下程序集属性的Startup类
[assembly:OwinStartup(typeof(Startup))]

我还为WebApi使用Swagger接口,并通过nuget包安装它.安装添加了SwaggerConfig类,其中包含以下程序集属性
[assembly:PreApplicationStartMethod(typeof(SwaggerConfig),“Register”)]

在启动WebApi时,程序集属性导致此异常.我从SwaggerConfig类中删除了程序集属性,一切正常.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读