{"id":4313,"date":"2014-03-30T09:50:24","date_gmt":"2014-03-30T09:50:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/upgrading-to-web-api-2-breaks-application-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:50:24","modified_gmt":"2014-03-30T09:50:24","slug":"upgrading-to-web-api-2-breaks-application-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/upgrading-to-web-api-2-breaks-application-collection-of-common-programming-errors\/","title":{"rendered":"Upgrading to Web API 2 breaks application-Collection of common programming errors"},"content":{"rendered":"<p>I have an Umbraco 7 application which uses V4.0 assemblies for things like System.Web.WebHost, System.Web.Http and related assemblies. I&#8217;m trying to get a Web API2 dll working with the Umbraco application, and am having a tough time.<\/p>\n<p>If I use assembly redirection to default to V5.0 assemblies, the app breaks when Umbraco loads and attempts to use a controller. The problem here is that in V5.0 of System.Web.Http, ApiController now has a check when setting Request. This check always fails and throws InvalidOperationException:<\/p>\n<pre><code>set\n{\n    if (value == null)\n    {\n        throw Error.PropertyNull();\n    }\n    HttpRequestContext requestContext = value.GetRequestContext();\n    HttpRequestContext httpRequestContext = this.RequestContext;\n    if (requestContext != null &amp;&amp; requestContext != httpRequestContext)\n    {\n        throw new InvalidOperationException(SRResources.RequestContextConflict);\n    }\n    this.ControllerContext.Request = value;\n    value.SetRequestContext(httpRequestContext);\n    RequestBackedHttpRequestContext requestBackedHttpRequestContext = httpRequestContext as RequestBackedHttpRequestContext;\n    if (requestBackedHttpRequestContext != null)\n    {\n        requestBackedHttpRequestContext.Request = value;\n    }\n}\n<\/code><\/pre>\n<p>The other thing I&#8217;m trying is to have both DLLs loaded and used appropriately. In this case I&#8217;m running into an error, but don&#8217;t know if I&#8217;m doing it correctly. All I&#8217;ve done is added folders to keep separate versions of the same dlls, and wire them up in the web.config using something like this:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>error: CS1705: Assembly &#8216;WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; uses &#8216;System.Web.Http, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8217; which has a higher version than referenced assembly &#8216;System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8217;<\/p>\n<p>Is there hope?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have an Umbraco 7 application which uses V4.0 assemblies for things like System.Web.WebHost, System.Web.Http and related assemblies. I&#8217;m trying to get a Web API2 dll working with the Umbraco application, and am having a tough time. If I use assembly redirection to default to V5.0 assemblies, the app breaks when Umbraco loads and attempts [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4313","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4313"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4313\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}