Ensure that HttpConfiguration.EnsureInitialized()

前端 未结 14 1012
一生所求
一生所求 2020-11-30 23:31

I\'ve installed Visual Studio 2013 and when I run my app I get the error below.

I\'ve got no idea as to where I\'m to initialized this object.

What to do?

相关标签:
14条回答
  • 2020-11-30 23:47

    I actually got this error when I was using Attribute Routing within my WebApi.

    I had

    [Route("webapi/siteTypes/{siteTypeId"]

    instead of

    [Route("webapi/siteTypes/{siteTypeId}"]

    for my route and got this error. I had simply missed out the closing curly bracket. Once I added it back in, this error didn't occur again.

    0 讨论(0)
  • 2020-11-30 23:49

    See @gentiane's answer below for the correct way to handle this now.

    At the end of the Application_Start method in Global.Asax.cs try adding:-

    GlobalConfiguration.Configuration.EnsureInitialized(); 
    
    0 讨论(0)
  • 2020-11-30 23:52

    In my case I created the webservice in project A and started it from Project B and I got exactly this error. The problem was that some .dll-files which are required by A where missing in the build-output-folder of B. Ensure that these .dll-files are available fixed it.

    0 讨论(0)
  • 2020-11-30 23:55

    Although the above answer works if incase that is not set, In my case this stuff was set already. What was different was that, for one of the APIs I had written, I had prefixed the route with a / . Example

    [Route("/api/abc/{client}")] 
    

    .Changing this to

    [Route("api/abc/{client}")]
    

    fixed it for me

    0 讨论(0)
  • 2020-11-30 23:58

    Call

    GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
    

    before

    GlobalConfiguration.Configure(c => ...);
    

    completes its execution.

    0 讨论(0)
  • 2020-11-30 23:58

    I got this error when the version of Newtonsoft.Json was different in my main project compared to the helper project

    0 讨论(0)
提交回复
热议问题