{"id":3421,"date":"2022-10-10T20:59:22","date_gmt":"2022-10-10T20:59:22","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=3421"},"modified":"2022-10-10T20:59:22","modified_gmt":"2022-10-10T20:59:22","slug":"assembly-redirects-of-strong-named-assemblies","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/assembly-redirects-of-strong-named-assemblies\/","title":{"rendered":"Assembly Redirects of Strong-Named Assemblies"},"content":{"rendered":"<p>It&#8217;s unfortunately all too often recently that I&#8217;ve need to redirect assemblies, so I thought I&#8217;d write a quick post on the subject.<\/p>\n<p>Occasionally you may have a situation where one library (let&#8217;s call it Lib1) you&#8217;re using in .NET relies on a specific version of a another, strong-named, library (let&#8217;s call it Lib2). Then you go and update the library Lib2 to a newer version and things break. Lib1 expects a specific version of Lib2 and we&#8217;re not supplying it.<\/p>\n<p>Simple open\/add your App.config file &#8211; we then add something like this<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;runtime&gt;\r\n  &lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;\r\n    &lt;dependentAssembly&gt;\r\n      &lt;assemblyIdentity name=&quot;Lib2&quot; publicKeyToken=&quot;Lib2-PublicToken&quot; culture=&quot;neutral&quot; \/&gt;\r\n      &lt;bindingRedirect oldVersion=&quot;0.0.0.0-1.0.0.0&quot; newVersion=&quot;2.0.0.0&quot; \/&gt;\r\n    &lt;\/dependentAssembly&gt;\r\n  &lt;\/assemblyBinding&gt;\r\n&lt;\/runtime&gt;\r\n<\/pre>\n<p>Obviously you replace Lib2 with the assembly that your code is dependent upon, you&#8217;ll also need to supply the publicKeyToken. The oldVersion is a range of versions from 0.0.0.0 to 1.0.0.0 in this case, meaning anything that required this assembly version 0 to 1 should now use version 2 (2.0.0.0).<\/p>\n<p>When adding further assembly redirects we of just supply further dependentAssembly elements.<\/p>\n<p>To find the publicKeyToken we can use the Strong Name utility (sn.exe) which can be found here (for example) <\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&quot;%ProgramFiles%\\\\Microsoft SDKs\\Windows\\v8.0A\\bin\\NETFX 4.0 Tools\\sn.exe&quot; -T &lt;assemblyName&gt;\r\n<\/pre>\n<p>We can also find such information via the likes of ILSpy, by clicking on the assembly and in the right hand pane we&#8217;ll have information such as<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\/\/ Microsoft.VisualC, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\r\n<\/pre>\n<p><strong>Further Reading<\/strong><\/p>\n<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/wd40t7ad(v=vs.110).aspx\" target=\"_blank\" rel=\"noopener\">Strong-Named Assemblies<\/a><br \/>\n<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/7wd6ex19(v=vs.110).aspx\" target=\"_blank\" rel=\"noopener\">Redirecting Assembly Versions<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s unfortunately all too often recently that I&#8217;ve need to redirect assemblies, so I thought I&#8217;d write a quick post on the subject. Occasionally you may have a situation where one library (let&#8217;s call it Lib1) you&#8217;re using in .NET relies on a specific version of a another, strong-named, library (let&#8217;s call it Lib2). Then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[],"class_list":["post-3421","post","type-post","status-publish","format-standard","hentry","category-net"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=3421"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3421\/revisions"}],"predecessor-version":[{"id":9556,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3421\/revisions\/9556"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=3421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=3421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=3421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}