3

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?

santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
  • Are you able to provide us with more information or code samples? What does your StructureMap configuration look like? – Joseph Woodward Apr 17 '15 at 12:41
  • Please follow the below steps to reproduce the issue: 1. Create a web api 2 project using empty template of VS2013. 2. Add the nuget package StructureMap.WebApi2 nuget package for Web API 2 project. 3. Take a web api controller sample (for example TestController.cs) and put some sample code and run the project. 4. You will be getting the error as mentioned in the query above. – santosh kumar patro Apr 18 '15 at 13:12

0 Answers0