1

I got this exception "Could not load file or assembly System.Web.Http, Version=4.0.0.0" when starting my WebApi application, I register in the AppStart method.

    protected void Application_Start()
    {
        RegisterInjector();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);           

    }
    private void RegisterInjector()
    {

        var container = new Container();
        container.Verify();
        GlobalConfiguration.Configuration.DependencyResolver =
     new SimpleInjectorWebApiDependencyResolver(container);
    }
5
  • What version of System.Web.Http you have in your bin folder? Commented Jun 10, 2014 at 2:08
  • Version5.0.0.0, Do I need to use 4.0.0.0? Commented Jun 10, 2014 at 2:12
  • i am using MVC 5 and WebAPI 2, does simple injector support that? Commented Jun 10, 2014 at 2:22
  • 2
    Use a bindingRedirect, see here Commented Jun 10, 2014 at 3:24
  • So you mean i force it to bind to the version 5.0.0.0? Commented Jun 10, 2014 at 6:07

1 Answer 1

1

The Simple Injector integration package for Web API references the lowest required version of the System.Web.Http assembly and the accepted way of upgrading to a newer version is by configuring a bindingRedirect in your config file that forces .NET to use the newer System.Web.Http assembly. When installing packages through Nuget, these binding redirects are automatically managed for you (or at least - most of the time) and in that case it is not something you have to do manually.

In other cases, you will have to add the binding direct manually to your application's configuration file:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="b03f5f7f11d50a3a" 
            culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, i just find i have to do it manually though i use nuget to install the webapi integrated one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.