How to inject HttpRequestMessage in OWIN environment?

Nov 24, 2014 at 7:00 PM
I'm running Web API using OWIN and this extensions method:
 container.EnableHttpRequestMessageTracking(GlobalConfiguration.Configuration)
throws this exception:
System.MissingMethodException:
Method not found: 'System.Collections.ObjectModel.Collection`1<System.Net.Http.DelegatingHandler> System.Web.Http.HttpConfiguration.get_MessageHandlers()'.
   at SimpleInjector.SimpleInjectorWebApiExtensions.EnableHttpRequestMessageTracking(Container container, HttpConfiguration configuration)
Coordinator
Nov 24, 2014 at 7:03 PM
Which version of System.Web.Http are you using?
Nov 24, 2014 at 7:06 PM
System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

[assembly: AssemblyFileVersion("5.2.20826.0")]
[assembly: AssemblyInformationalVersion("5.2.2-20826 (66298100f4e349d3812b1aad32c5278c256a2cdd)")]

<package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net452" />
Coordinator
Nov 24, 2014 at 7:20 PM
That's weird. The Web API integration package depends on System.Web.Http version 4.0 and references the System.Web.Http NuGet package. The Microsoft.AspNet.WebApi.Core NuGet package also contains the System.Web.Http.dll. And I just took a look into version 5.2.2.0 of the System.Web.Http.dll and the System.Web.Http.HttpConfiguration class does contain the get_MessageHandlers() method just as 4.0 does.

So I'm unable to see why you would get this exception. Do you accidentally use some experimental version, or do you have two versions of the System.Web.Http.dll loaded at runtime?
Nov 24, 2014 at 8:32 PM
Edited Nov 24, 2014 at 8:36 PM
According to Debug->Modules I have only 1 System.Web.Http.dll which was copied from \packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45 to "Temporary ASP.NET Files". I wiped out this folder but it didn't help,

Opening the dll with Reflector I can see the property:
public Collection<DelegatingHandler> MessageHandlers
{
    get
    {
        return this._messageHandlers;
    }
}
When I build SimpleInjector.WebApi from the source it doesn't work still, VS even doesn't step-into, throws an exception immediately.
Once I referenced System.Web.Http.dll ver 5.2 from the nuget package (rather then ver 4.0 from GAC) it worked.

It's called binary incompatibility (due a reason I don't understand too), right?
Nov 25, 2014 at 6:17 PM
Hey Steven, any thoughts on this, please?
Coordinator
Nov 25, 2014 at 6:52 PM
I'm sorry, but I'm not sure what's going on here. I never had any complaint about the Web API integration package not working, while I had contact with several developers who are using Web API. Furthermore, although you couldn't get the Simple Injector source code compiling, it compiles fine on my development machine. So I'm a bit clueless here about what might causing this in your case.