Every now and again you hit what seems like a simple problem only to dig deeper and find it’s not as straight forward as first thought…Today was one such time. A simple upgrade of an Azure application to the latest version of the Azure SDK (2.8 at the time of writing this). Everything is updated, compiled, tested, and running locally. Then deployed to Azure and… bang!
The full error reads:
Could not load file or assembly ‘Microsoft.WindowsAzure.Diagnostics, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35’
Surely this should have affected the app when running locally too, and even if it didn’t it’s simple to fix. Just add a binding redirect (in this case in my web.config file).
<dependentAssembly> <assemblyIdentity name="Microsoft.WindowsAzure.Diagnostics" publicKeyToken="31bf3856ad364e35" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-188.8.131.52" newVersion="184.108.40.206"/> </dependentAssembly>
Simple right… Not quite.
Looking deeper at the stack trace you’ll see:
When you’re using IIS (like we are) the startup process for your app is handled by WAIISHost.exe not but w3wp.exe (aka. the worker process). This means that the web.conf file isn’t applicable and the binding redirect is useless here.
There are various blog posts and stack overflow questions/answers about this. A lot of them mention adding an App.config file or a WaIISHost.exe.config file. Neither of these worked with the full IIS hosting model and Azure SDK 2.8.
Solved: I had to add a file <WebProjectName>.dll.config and set it to copy always. Once that was packaged and deployed the app started as normal and the binding redirect worked fine. For reference here is the contents of my <WebProjectName>.dll.config
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.WindowsAzure.Diagnostics" publicKeyToken="31bf3856ad364e35" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-220.127.116.11" newVersion="18.104.22.168"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Hopefully this helps anyone else who finds themselves in a similar position with all of the binding rediects in place but still not working when deploying to Azure.