gpt4 book ai didi

c# - 确保 HttpConfiguration.EnsureInitialized()

转载 作者:IT王子 更新时间:2023-10-29 03:32:40 24 4
gpt4 key购买 nike

我已经安装了 Visual Studio 2013,当我运行我的应用程序时,出现以下错误。

我不知道要在哪里初始化这个对象。

怎么办?

    Server Error in '/' Application.

The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.

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.InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.

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:


[InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.]
System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() +101
System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) +63
System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext) +107
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +233
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

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

这是给 AlumCloud

最佳答案

如果您在 Application_Start 结束时执行此操作,则为时已晚,因为已调用 WebApiConfig.Register。

解决此问题的最佳方法是通过在 Global.asax 中替换来使用新的初始化方法:

WebApiConfig.Register(GlobalConfiguration.Configuration);

通过

GlobalConfiguration.Configure(WebApiConfig.Register);

关于c# - 确保 HttpConfiguration.EnsureInitialized(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19969228/

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