gpt4 book ai didi

c# - WebActivatorEx 在应用程序启动时导致 ArgumentException

转载 作者:行者123 更新时间:2023-11-30 13:11:57 24 4
gpt4 key购买 nike

在安装 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 Framework 为目标,但是我注意到在底部的堆栈跟踪中它显示为 Microsoft .NET 4 Framework Version:4.0.30319 我不确定这是否正确。

最佳答案

我将 OWIN 中间件与 WebApi 一起使用,因此需要一个具有以下程序集属性的 Startup 类[程序集:OwinStartup(typeof(Startup))]

我还使用 WebApi 的 Swagger 接口(interface)并通过 nuget 包安装它。安装添加了具有以下程序集属性的 SwaggerConfig 类[程序集:PreApplicationStartMethod(typeof(SwaggerConfig),“注册”)]

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

关于c# - WebActivatorEx 在应用程序启动时导致 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31054522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com