Ensure That Httpconfiguration.Ensureinitialized()

Ensure that HttpConfiguration.EnsureInitialized()

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(); 

What is GlobalConfiguration.Configuration.EnsureInitialized() in Global.asax ASP.Net Web API

Per MSDN:

HttpConfiguration.EnsureInitialized Method

Invoke the Intializer hook. It is considered immutable from this point forward. It's safe to call this multiple times.

More Information

As this answer points out, this was likely put into your application at some point because of a change to the way that Web API is supposed to be registered in Web API v1 vs Web API v2.

Anyone who didn't make the change after upgrading Web API would have received the error message:

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

Unfortunately, the solution given in the error message is misleading. What you are actually supposed to change while upgrading from V1 is to replace this line:

WebApiConfig.Register(GlobalConfiguration.Configuration);

with this line:

GlobalConfiguration.Configure(WebApiConfig.Register);

The latter method internally calls EnsureInitialized so you don't have to from your startup code.

I noticed that you don't have either of these Web Api initializers in your configuration, so I would recommend that you change your startup as follows:

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}

Explain the quantile() function in R

You're understandably confused. That documentation is terrible. I had to go back to the paper its based on (Hyndman, R.J.; Fan, Y. (November 1996). "Sample Quantiles in Statistical Packages". American Statistician 50 (4): 361–365. doi:10.2307/2684934) to get an understanding. Let's start with the first problem.

where 1 <= i <= 9, (j-m)/n <= p < (j-m+1)/ n, x[j] is the jth order statistic, n is the sample size, and m is a constant determined by the sample quantile type. Here gamma depends on the fractional part of g = np+m-j.

The first part comes straight from the paper, but what the documentation writers omitted was that j = int(pn+m). This means Q[i](p) only depends on the two order statistics closest to being p fraction of the way through the (sorted) observations. (For those, like me, who are unfamiliar with the term, the "order statistics" of a series of observations is the sorted series.)

Also, that last sentence is just wrong. It should read

Here gamma depends on the fractional part of np+m, g = np+m-j

As for m that's straightforward. m depends on which of the 9 algorithms was chosen. So just like Q[i] is the quantile function, m should be considered m[i]. For algorithms 1 and 2, m is 0, for 3, m is -1/2, and for the others, that's in the next part.

For the continuous sample quantile types (4 through 9), the sample quantiles can be obtained by linear interpolation between the kth order statistic and p(k):

p(k) = (k - alpha) / (n - alpha - beta + 1), where α and β are constants determined by the type. Further, m = alpha + p(1 - alpha - beta), and gamma = g.

This is really confusing. What the documentation calls p(k) is not the same as the p from before. p(k) is the plotting position. In the paper, the authors write it as pk, which helps. Especially since in the expression for m, the p is the original p, and the m = alpha + p * (1 - alpha - beta). Conceptually, for algorithms 4-9, the points (pk, x[k]) are interpolated to get the solution (p, Q[i](p)). Each algorithm only differs in the algorithm for the pk.

As for the last bit, R is just stating what S uses.

The original paper gives a list of 6 "desirable properties for a sample quantile" function, and states a preference for #8 which satisfies all by 1. #5 satisfies all of them, but they don't like it on other grounds (it's more phenomenological than derived from principles). #2 is what non-stat geeks like myself would consider the quantiles and is what's described in wikipedia.

BTW, in response to dreeves answer, Mathematica does things significantly differently. I think I understand the mapping. While Mathematica's is easier to understand, (a) it's easier to shoot yourself in the foot with nonsensical parameters, and (b) it can't do R's algorithm #2. (Here's Mathworld's Quantile page, which states Mathematica can't do #2, but gives a simpler generalization of all the other algorithms in terms of four parameters.)

Why do I get an InvalidOperationException when I try to use attribute routing with Web API 2?

In Global.asax, the Application_Start event needs to change from

WebApiConfig.Register(GlobalConfiguration.Configuration);

to:

GlobalConfiguration.Configure(WebApiConfig.Register);

ASP.NET web API gives 404 no matter what

you can refer to Ian Mercer and gentiane's anwser in Ensure that HttpConfiguration.EnsureInitialized() if you have no port conflict.

hope it helps.

Error with WebApi 2.0 RouteAttribute

Please remove

    GlobalConfiguration.Configure(x => x.MapHttpAttributeRoutes());

from Global.asax.

And then call MapHttpAttributeRoutes in the WebApiConfig.cs

    public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
}

A direct route AND The object has not yet been initialized errors, WebAPI

After searching the Internet for a very long time without finding a solution, I recreated the project from scratch and that solved the issue.
It seems to be some kind of bug in Visual Studio 2013.

Web API Attribute Routing not working when less than 4 parts to route

You need to re-order your registration code above as your request url is being matched by MVC routes as its more generic (ex: {controller}/{action}/{id}) compared to Web API's specific route (api/{controller}/{id}). As per routing guidelines, more specific routes must be registered before generic routes.

    protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);

RouteConfig.RegisterRoutes(RouteTable.Routes);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}


Related Topics



Leave a reply



Submit