Casting HttpRequestMessage.Properties["MS_RequestContext"] to OwinHttpRequestContext
-
So this is weird. I'm trying to manually fiddle with a property of my MS_RequestContext during Controller Activation inside my WebApi's CompositionRoot. my Create method receives a System.Net.Http.HttpRequestMessage argument. I can drill down request to grab
request.Properties["MS_RequestContext"]
Properties is a
dictionary
That object will be an OwinHttpRequestContext at runtime. But whenever I attempt to cast, so that I can access the properties on the RequestContext, I get a naughty-gram from Visual Studio
(request.Properties["MS_RequestContext"] as OwinHttpRequestContext).Request.Properties;
The error that comes back is:
The type or namespace 'OwinHttpRequestContext' could not be found (are you missing a using directive or an assembly reference?)
Well...OwinHttpRequestContext lives inside the System.Web.Http.Owin namespace. My references are all set up. I even have added a using statement for good measure. So the crazy part is that if I remove my code that attempts to directly reference request.Properties, but instead set a breakpoint inside my Create method, I can -through a watch- execute
(request.Properties["MS_RequestContext"] as System.Web.Http.Owin.OwinHttpRequestContext).Request.Properties
without issue. I can confirm that I have no problem modifying the properties at runtime through the immediate window. Why am I not able to perform this same cast at build time? I've inspected the
HttpContext.Current.GetOwinContext()
for access to the property that I need to manipulate, but it's not available on IOwinContext.
"I need build Skynet. Plz send code"