{"id":633,"date":"2012-08-29T09:48:38","date_gmt":"2012-08-29T09:48:38","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2012\/08\/29\/odata-101-bin-deploying-wcf-data-services\/"},"modified":"2024-02-12T16:23:04","modified_gmt":"2024-02-12T23:23:04","slug":"odata-101-bin-deploying-wcf-data-services","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/odata-101-bin-deploying-wcf-data-services\/","title":{"rendered":"OData 101: Bin deploying WCF Data Services"},"content":{"rendered":"<p><strong>TL;DR:<\/strong> If you\u2019re bin-deploying WCF Data Services you need to make sure that the .svc file contains the right version string (or no version string).<\/p>\n<p>The idea for this post originated from an email I received yesterday. The author of the email, <a href=\"https:\/\/george.tsiokos.com\" target=\"_blank\" rel=\"noopener\">George Tsiokos<\/a> (<a href=\"https:\/\/twitter.com\/gtsiokos\" target=\"_blank\" rel=\"noopener\">@gtsiokos<\/a>), complained of a bug where updating from WCF Data Services 5.0 to 5.0.1 broke his WCF Data Service. Upon investigation it became clear that there was an easy fix for the short-term, and perhaps something we can do in 5.1.0 to make your life easier in the long-term.<\/p>\n<h3>What\u2019s Bin Deploy?<\/h3>\n<p>We\u2019ve been <a href=\"http:\/\/blogs.msdn.com\/b\/astoriateam\/archive\/2012\/05\/17\/nuget-and-bin-deploy.aspx\" target=\"_blank\" rel=\"noopener\">blogging about<\/a> our goals for bin deploying applications for a while now. In a nutshell, bin deploy is the term for copying and pasting a folder to a remote machine and expecting it to work without any other prerequisites. In our case, we clearly still have the IIS prerequisite, but you shouldn\u2019t have to run an installer on the server that GACs the Microsoft.Data.Services DLL.<\/p>\n<p>Bin deploy is frequently necessary when dealing with hosted servers, where you may not have rights to install assemblies to the GAC. Bin deploy is also extremely useful in a number of other environments as it decreases the barriers to hosting a WCF Data Service. (Imagine not having to get your ops team to install something in order to try out WCF Data Services!)<\/p>\n<h3>Replicating the Problem<\/h3>\n<p>First, let\u2019s walk through what\u2019s actually happening. I\u2019m going to do this in Visual Studio 2012, but this would happen similarly in Visual Studio 2010.<\/p>\n<p>First, create an <strong>Empty ASP.NET Web Application<\/strong>. Then right-click the project and choose <strong>Add &gt; New Item<\/strong>. Select <strong>WCF Data Service<\/strong>, assign the service a name, and click <strong>Add<\/strong>. (Remember that in Visual Studio 2012, the item template actually adds the reference to the NuGet package on your behalf. If you\u2019re in Visual Studio 2010, you should add the NuGet package now.)<\/p>\n<p>Stub enough code into the service to make it load properly. In our case, this is actually enough to load the service (though admittedly it\u2019s not very useful):<\/p>\n<pre class=\"prettyprint linenums\">using System.Data.Services;\r\n\r\nnamespace OData101.UpdateTheSvcFileWhenBinDeploying\r\n{\r\n    public class BinDeploy : DataService&lt;DummyContext&gt; { }\r\n\r\n    public class DummyContext { }\r\n}<\/pre>\n<p>Press F5 to debug the project. While the debugger is attached, open the Modules window (<strong>Ctrl+D,M<\/strong>). Notice that Microsoft.Data.Services 5.0.0.50627 is loaded:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/6825.image_thumb_4B184EC9.png\"><img decoding=\"async\" title=\"image\" style=\"border-width: 0px;padding-top: 0px;padding-right: 0px;padding-left: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/6825.image_thumb_4B184EC9.png\" width=\"430\" height=\"110\" \/><\/a><\/p>\n<p>Now update your NuGet package to 5.0.1 or some subsequent version. (In this example I updated to 5.0.2.) Debug again, and look at the difference in the Modules window:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/7418.image_thumb_1A84D111.png\"><img decoding=\"async\" title=\"image\" style=\"border-width: 0px;padding-top: 0px;padding-right: 0px;padding-left: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2012\/08\/7418.image_thumb_1A84D111.png\" width=\"584\" height=\"84\" \/><\/a><\/p>\n<p>In this case we have two versions of Microsoft.Data.Services loaded. We pulled 5.0.2 from the bin deploy folder and we still have 5.0.0.50627 loaded from the GAC. Were you to bin deploy this application as-is, it would fail on the server with an error similar to the following:<\/p>\n<p><i>Could not load file or assembly &#8216;Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8217; or one of its dependencies. The located assembly&#8217;s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)<\/i> <\/p>\n<p>So why is the service loading both assemblies? If you look at your .svc file (you need to right-click it and choose View Markup), you\u2019ll see something like the following line in it:<\/p>\n<pre class=\"prettyprint\">&lt;%@ ServiceHost Language=&quot;C#&quot; Factory=&quot;System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; Service=&quot;OData101.UpdateTheSvcFileWhenBinDeploying.BinDeploy&quot; %&gt;<\/pre>\n<p>That 5.0.0.0 string is what is causing the GACed version of Microsoft.Data.Services to be loaded.<\/p>\n<h3>Resolving the Problem<\/h3>\n<p>For the short term, you have two options:<\/p>\n<ol>\n<li>Change the version number to the right number. The first three digits (major\/minor\/patch) are the significant digits; assembly resolution will ignore the final digit. <\/li>\n<li>Remove the version number entirely. (You should remove the entire name\/value pair and the trailing comma.)<\/li>\n<\/ol>\n<p>Either of these changes will allow you to successfully bin deploy the service.<\/p>\n<h3>A Permanent Fix?<\/h3>\n<p>We\u2019re looking at what we can do to provide a better experience here. We believe that we will be able to leverage the PowerShell script functionality in NuGet to at least advise, if not outright change, that value.<\/p>\n<p>So what do you think? Would you feel comfortable with a package update making a change to your .svc file? Would you rather just have a text file pop up with a message that says you need to go update that value manually? Can you think of a better solution? We\u2019d love to hear your thoughts and ideas in the comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR: If you\u2019re bin-deploying WCF Data Services you need to make sure that the .svc file contains the right version string (or no version string). The idea for this post originated from an email I received yesterday. The author of the email, George Tsiokos (@gtsiokos), complained of a bug where updating from WCF Data Services [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[49,89],"class_list":["post-633","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-odata-101","tag-workarounds"],"acf":[],"blog_post_summary":"<p>TL;DR: If you\u2019re bin-deploying WCF Data Services you need to make sure that the .svc file contains the right version string (or no version string). The idea for this post originated from an email I received yesterday. The author of the email, George Tsiokos (@gtsiokos), complained of a bug where updating from WCF Data Services [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}