I have used StructureMap.WebApi2 nuget package for Web API 2 project. The Web API controllers use constructor injection to inject a repository dependency which should be resolved by StructureMap Ioc.. Now when I try to run the project I am always getting the below mentioned error: Value cannot be null. Parameter name: httpContext I tried to check the InnerException but it has null value. I am getting this exception from the StructureMapDependencyScope.cs StackTrace: at System.Web.HttpContextWrapper..ctor(HttpContext httpContext) at DemoStructureMapWebAPI.DependencyResolution.StructureMapDependencyScope.get_HttpContext() in c:\Users\sapatro\Documents\Visual Studio 2013\Projects\DemoStructureMapWebAPI\DemoStructureMapWebAPI\DependencyResolution\StructureMapDependencyScope.cs:line 69 at DemoStructureMapWebAPI.DependencyResolution.StructureMapDependencyScope.get_CurrentNestedContainer() in c:\Users\sapatro\Documents\Visual Studio 2013\Projects\DemoStructureMapWebAPI\DemoStructureMapWebAPI\DependencyResolution\StructureMapDependencyScope.cs:line 55 at DemoStructureMapWebAPI.DependencyResolution.StructureMapDependencyScope.Dispose() in c:\Users\sapatro\Documents\Visual Studio 2013\Projects\DemoStructureMapWebAPI\DemoStructureMapWebAPI\DependencyResolution\StructureMapDependencyScope.cs:line 85 at DemoStructureMapWebAPI.App_Start.StructuremapMvc.End() in c:\Users\sapatro\Documents\Visual Studio 2013\Projects\DemoStructureMapWebAPI\DemoStructureMapWebAPI\App_Start\StructuremapMvc.cs:line 44 On checking the code I found that the below mentioned code is giving error which is part of StructureMapDependencyScope.cs
private HttpContextBase HttpContext {
get {
var ctx = Container.TryGetInstance<HttpContextBase>();
return ctx ?? new HttpContextWrapper(System.Web.HttpContext.Current);
}
}
Can anyone suggest me the best possible ways to resolve the above issue?