无法加载文件或程序集“Microsoft.WindowsAzure.Diagnostics”或其某个依赖项。

11

我的系统几天前崩溃了,自那以后当我尝试调试本地的Azure环境时,出现了这个错误“Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics' or one of its dependencies”。

我已重新安装以下软件(Windows Azure tools for MS VS 2012 June 2012 sp1,Windows Azure emulator - June 2012,Windows Azure Librarires for .net - June 2012)。

仍然遇到同样的问题,请问有什么建议?

=== Pre-bind state information ===
LOG: User = ...........
LOG: DisplayName = Microsoft.WindowsAzure.Diagnostics
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.WindowsAzure.Diagnostics | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Projects/Client/Connection Intelegence/CICloud/CIWebRole/
LOG: Initial PrivatePath = C:\Projects\Client\Connection Intelegence\CICloud\CIWebRole\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\Client\Connection         Intelegence\CICloud\CIWebRole\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9cc4e65f/1fb72ae3/Microsoft.WindowsAzure.Diagnostics.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9cc4e65f/1fb72ae3/Microsoft.WindowsAzure.Diagnostics/Microsoft.WindowsAzure.Diagnostics.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Client/Connection Intelegence/CICloud/CIWebRole/bin/Microsoft.WindowsAzure.Diagnostics.DLL.
LOG: Using application configuration file: C:\Projects\Client\Connection Intelegence\CICloud\CIWebRole\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35



[FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
[FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12761078
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

你解决了吗?我刚刚遇到了一个崩溃,什么都不好使了 - 出现了同样的错误。 - Wojtek Turowicz
5个回答

8
看起来这是在您的应用程序启动时发生的。请查看您的web.config,您是否有一个跟踪侦听器指向Microsoft.WindowsAzure.Diagnostics程序集?那可能是您的应用程序无法工作的原因。
首先,请查看您的程序集引用并删除Microsoft.WindowsAzure.Diagnostics(以确保我们不使用旧版本)。然后,添加对Microsoft.WindowsAzure.Diagnostics的引用,但请确保这是1.7.0.0版本。
您应该在以下位置找到此程序集的正确版本:C:\Program Files\Microsoft SDKs\Windows Azure.NET SDK\2012-06\ref

我有1.7.0.0的参考文献。顺便说一句:这在Azure上可以工作,只是本地开发时出现了问题。必须是损坏或缺少文件。我已经修复了它们,但问题仍然存在。 - Floyd
非常感谢!我已经更新了所有引用,但是并不知道跟踪侦听器! - dopplesoldner

5

我知道这是一个老话题,但它仍然是谷歌搜索“Could not load file or assembly Microsoft.WindowsAzure.Diagnostics” 的顶级结果。以下是我的解决方法:

在使用 Azure SDK 2.7.1 和 Visual Studio 2013 时,我遇到了这个问题。在升级到 Windows 10 和 Azure SDK 2.7 之间的某个地方,安装过程出了问题。我尝试重新安装 Azure SDK,升级到 Visual Studio 2015,但都没有起作用。最终,我不得不更改我的 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>

为了

    <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>

注意从“2.7.0.0”到“2.5.0.0”的变化。对我来说,Microsoft.WindowsAzure.Diagnostics 2.7.0.0 DLL不存在。回滚到2.5.0.0可以正常工作。我仍然希望找到根本原因,但我有更重要的事情要处理。希望这可以帮到你!


我的版本是从2.5.0.0升级到2.8.0.0。 - Catwood

4

在Sandrinio的答案基础上补充一点(很抱歉我没有足够特权),我曾遇到类似的错误,其中我的web.config文件中指向版本1.0.0.0,但实际上引用了1.7.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>

我将其注释掉后问题得到解决。


1

我查看了参考资料,发现Microsoft.WindowsAzure.Diagnostics被角色使用。在我的情况下,角色正在使用2.8.0.0版本。然后,我打开了每个角色的app.config,并将Microsoft.WindowsAzure.Diagnostics的add设置为相同的版本。

  <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>

1
最好检查Microsoft.WindowsAzure.Diagnostics的属性来确定你使用的版本。当我将我的版本2.8.0.0插入到Web.config元素中时,它可以像Dan和Taylor上面提到的一样工作。对我而言,2.7.0.0无法工作,但明天可能会有所不同;-)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接