Issue with webapi attribute routing.

Vote:
 

Hi Team,

Recently I have upgraded to the GlobalLink 11.4.3 version. But after upgrade we are facing object not initialized issue in our application.

We have web api attribute routine defined in WebApiConfig.cs initialize model. See below code for reference,

[InitializableModule]
[ModuleDependency(typeof(FrameworkInitialization))]
public class WebApiConfig : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
// Enable Web API routing
GlobalConfiguration.Configure(config =>
{
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
});
}
/// <inheritdoc />
public void Uninitialize(InitializationEngine context)
{
}
}

config.MapHttpAttributeRoutes(); is creating problem with GlobalLink 11.4.3.

when I comment this line application works but the web api's not working. I tried to add this in register method and injected dependency in Application_Start methos as well but still its not working.

Please suggest something so that I can use GlobalLink latest version and attribute routine seemlessly in my application.

Thanks,

Rahul Dikkar

#205807
Jul 24, 2019 10:15
Vote:
 

Hi Rahul,

Could you please attach the exact error here?

Thanks

Ravindra

#205809
Jul 24, 2019 10:33
Vote:
 
This exeception is coming on browsing.

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. at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)
#205811
Jul 24, 2019 11:39
Vote:
 

I'm having the same issue. GlobalLink is involved here as well. It seems GlobalLinks configuration takes precedence over mine. Rahul Dikkar, did you manage to solve this?

#207864
Oct 07, 2019 15:16
Rahul Dikkar - Jan 16, 2020 7:10
I am able to resolve this by removing the [ModuleDependency(typeof(FrameworkInitialization))] from "WebApiConfig.cs".
Vote:
 

This issue is resolved.

#215864
Jan 16, 2020 7:11
Vote:
 

Coming late here, but I've actually writen a blog post about this kind of an issue: https://swapcode.wordpress.com/2020/01/12/broken-web-api-attribute-routing/

In short, most likely the issue is caused by a third party add-on which is calling 'GlobalConfiguration.Configure' method but not calling in the implementation to 'config.MapHttpAttributeRoutes()' - and when your code tries to call the Configure method mapping the http attribute routes it will not work as the Configure method has one time logic (Configure method can be called many times but the MapHttpAttributeRoutes() call must be done when called the first time otherwise it will not work in the later calls).

#215931
Jan 19, 2020 9:41
Vote:
 

Thank you @Antti Alasvuo! Your answer 100% applicable in my case. 

#215951
Jan 20, 2020 10:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.