3
votes

I just updated my installed projects from NuGet and got the unhandled exception below at runtime:

Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The exception was thrown from NinjectWebCommon. The bootstraper.Initialize(CreateKernel); line of code was the offender.

 public static void Start()
 {
     DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
     DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
     bootstrapper.Initialize(CreateKernel);
 }

I assume that Ninject may have a dependency on the old version of System.Web.Http, but don't want to rollback if I don't have to.

Has anyone had this problem and solved it?

EDIT

It seems as though the offending code is inside the bootstrapper.Initialize() method:

private static IKernel CreateKernel()
{
    var kernel = new StandardKernel();
    kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
    kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

    RegisterServices(kernel);

    // Set Web API Resolver (using WebApiContrib.Ioc.Ninject)
    GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(kernel);

    return kernel;
}

When I commented out the line of code under the existing comment the project ran fine. Will need to figure out how to get WebApi to work without WebApiContrub.IoC.Ninject...

1
were you able to solve this? I'm not getting the exception anymore after suggested solution, but DI not working... - developer82

1 Answers

9
votes

Sounds like you are using Web API2 without assembly binding redirect

<dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>