我已经安装了Visual 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的
发布于 2013-11-14 06:07:53
现在,请参阅@龙胆的答案如下以正确的方式处理此问题。
在Application_Start方法末尾的Global.Asax.cs中,尝试添加:-
GlobalConfiguration.Configuration.EnsureInitialized(); 发布于 2014-01-04 22:26:17
如果您在Application_Start的末尾执行此操作,将为时已晚,因为WebApiConfig.Register已经被调用。
解决这一问题的最佳方法是使用新的初始化方法,在Global.asax中替换:
WebApiConfig.Register(GlobalConfiguration.Configuration);通过
GlobalConfiguration.Configure(WebApiConfig.Register);发布于 2015-01-21 11:13:08
实际上,当我在我的WebApi中使用属性路由时,我得到了这个错误。
我有
路线(“webapi/siteTypes/{siteTypeId”)
而不是
路由(“webapi/siteTypes/{siteTypeId}”)
我的路线,并得到了这个错误。我只是错过了即将结束的卷曲括号。一旦我把它加回去,这个错误就不会再发生了。
https://stackoverflow.com/questions/19969228
复制相似问题