Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics' or one of its dependencies

我的未来我决定 提交于 2019-12-04 01:57:14

It looks like this is happening when your application starts. Take a look at your web.config, do you have a trace listener pointing to the Microsoft.WindowsAzure.Diagnostics assembly? That might be the reason why your application is not working.

First, take a look at your assembly references and delete Microsoft.WindowsAzure.Diagnostics should it be present (just to be sure we don't use old versions). Then, add a reference to Microsoft.WindowsAzure.Diagnostics, but make sure this is version 1.7.0.0.

You should find the right version of this assembly in: C:\Program Files\Microsoft SDKs\Windows Azure.NET SDK\2012-06\ref

Adding to Sandrinio's answer (sorry I don't have privilege) I had a similar error where 1.7.0.0 was being referenced but this section in my web.config pointed to version 1.0.0.0

<system.diagnostics>
<trace>
  <listeners>
    <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="AzureDiagnostics">
      <filter type="" />
    </add>
  </listeners>
</trace>

I commented it out and the problem was resolved.

I know this is an old topic but it's still the top Google result for "Could not load file or assembly Microsoft.WindowsAzure.Diagnostics", so here is what I did:

This was happening to me with the Azure SDK 2.7.1 and Visual Studio 2013. Somewhere between upgrading to Windows 10 and Azure SDK 2.7, something didn't get installed right. I tried reinstalling the Azure SDK, upgrading to Visual Studio 2015 but neither worked. I finally had to change the following line in my app.config:

    <system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>
</system.diagnostics>

to

    <system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>
</system.diagnostics>

Notice the change from "2.7.0.0" to "2.5.0.0". For me, Microsoft.WindowsAzure.Diagnostics 2.7.0.0 DLL did not exist. Reverting back to 2.5.0.0 works fine. I'd still like to find the root cause but I have more important things to move on to. Hope this helps!

It might be best to check the properties of Microsoft.WindowsAzure.Diagnostics to see which version you're using. Mine says 2.8.0.0 when I plugged that into the Web.config element mentioned by Dan and Taylor above it worked. 2.7.0.0 didn't work for me 2.8.0.0 did but tomorrow it may be otherwise ;-).

I looked at the references and discovered that Microsoft.WindowsAzure.Diagnostics is used by the roles. In my case, the roles were using 2.8.0.0. I then opened the app.config of each role and set the add for Microsoft.WindowsAzure.Diagnostics to that same version.

  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!