【问题标题】:Couldn't find type for class Microsoft.WindowsAzure.Diagnostics找不到 Microsoft.WindowsAzure.Diagnostics 类的类型
【发布时间】:2014-01-25 11:00:43
【问题描述】:

刚从假期回来,在我们的应用程序中进行了一些小的更改,当我遇到这个错误时:

找不到类 Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener、Microsoft.WindowsAzure.Diagnostics、Version=2.1.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35 的类型。

在假期回来之前,代码一直运行良好。它最后一次发布到 Azure 是在 3 周前,现在那里也有同样的问题。在本地,我尝试通过删除添加添加以下配置部分来修复它:

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

添加添加和删除对程序集的引用:

当我在本地调试项目时,Visual Studio 在以下行中断:

NewRelic.Api.Agent.NewRelic.IgnoreTransaction();

直到 2 天前(根据错误日志),这一直在本地和生产中工作。

全栈跟踪:

[ConfigurationErrorsException: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.]
   System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) +6755367
   System.Diagnostics.TypedElement.BaseGetRuntimeObject() +45
   System.Diagnostics.ListenerElement.GetRuntimeObject() +83
   System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() +143
   System.Diagnostics.TraceInternal.get_Listeners() +181
   System.Diagnostics.TraceInternal.WriteLine(String message) +119
   System.Diagnostics.Trace.WriteLine(String message) +4
   NewRelic.Api.Agent.NewRelic.IgnoreTransaction() +13
   Linklicious2.Controllers.ApiController.GetLinksToPing(Boolean test) +46
   lambda_method(Closure , ControllerBase , Object[] ) +98
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
   System.Web.Mvc.Controller.ExecuteCore() +106
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9631764
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

【问题讨论】:

    标签: c# azure newrelic azure-diagnostics


    【解决方案1】:

    如果您没有在模拟器中运行,请在此处查看我的 SO 答案 - How to solve Windows Azure Diagnostic Runtime Error (Could not create WindowsAzure.Diagnostics, Version=xx, Culture=neutral, PublicKeyToken=xx。基本上,只需添加:

    <filter level="TraceEventType.Error" />
    

    &lt;listeners&gt;&lt;add&gt; 部分。

    【讨论】:

    • 应该是type,而不是level
    【解决方案2】:

    虽然我的云服务包中有Microsoft.WindowsAzure.Diagnostics.dll 的项目引用和本地副本,但事实证明,您还需要包中MonAgentListener.dll 的副本 - 添加该文件后它开始工作再次。

    具体来说,我使用的是Microsoft.WindowsAzure.Diagnostics.dll 版本2.8.0.0,它的大小是35,608 bytes (34.7KB)。和C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Microsoft.WindowsAzure.Diagnostics.dll是同一个文件。

    MonAgentListener.dll版本33.1.5.074,448 bytes(72.7KB)大小,和C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\MonAgentListener.dll是同一个文件。

    不要将Microsoft.WindowsAzure.Diagnostics.dll 的 35KB 版本与C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Windows Azure Tools Diagnostics 1.0\Microsoft.WindowsAzure.Diagnostics.dllC:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Windows Azure Tools\v2.9\Microsoft.WindowsAzure.Diagnostics.dll 的 311KB 版本混淆,两者都标记为版本2.4.6489.4

    我的项目使用的是 Azure PaaSDiagnostics extension(这是 Azure PowerShell 和 Azure 门户使用的),而不是较旧的 Microsoft.WindowsAzure.Plugins.Diagnostics plugin云服务诊断版本(使用现在过时的“插件”模型而不是当前的“扩展”模型)。鉴于扩展旨在针对任何云服务工作 - 事实证明您仍然需要引用这些程序集并将它们包含在您的包中 - 扩展不会为您做这件事

    但是让事情变得更加混乱:如果你有一个 VS 云服务项目,那么如果你使用 VS 的云项目部署系统,那么 Visual Studio 2015 甚至 Visual Studio 2017 仍然使用旧的插件系统。

    (鉴于“云服务”系统是遗留系统,仅受较旧的 Azure“服务管理”API 支持,并且不受当前一代“资源管理”API 和系统的支持,因此 MS 不支持也就不足为奇了投资于改进 Visual Studio 中的云服务工具 - 但是插件与扩展(用于诊断和远程桌面)之间的这种混淆将我的项目推迟了数周,同时我研究了我应该做什么。

    还要确保您的云服务对Microsoft.WindowsAzure.ServiceRuntime.dll 的引用设置了Copy Local = True。这也会将文件 WindowsAzureEventSource.dllWindowsAzureTelemetryEvents.dll 复制到您的输出中 - 并确保所有 3 个文件都包含在您的云服务包中。

    TL;DR:

    1. 确保您的云服务包文件中有这些文件(以便在部署时将它们部署到E:\approot

      File                                       Version        Size (bytes)
      Microsoft.WindowsAzure.Diagnostics.dll           2.8.0.0        35,608
      MonAgentListener.dll                            33.1.5.0        74,448
      Microsoft.WindowsAzure.ServiceRuntime.dll   2.7.1198.768       158,624
      WindowsAzureEventSource.dll                 2.7.1198.768        83,872
      WindowsAzureTelemetryEvents.dll             2.7.1198.768        24,992
      
    2. 还要确保您的云服务 Worker Role 项目 有一个 App.config 文件,其中包含:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
          <system.diagnostics>
              <trace>
                  <listeners>
                      <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,Microsoft.WindowsAzure.Diagnostics,Version=2.8.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                          <!-- Ignore the VS-generated message "The attribute 'type' is not allowed." -->
                          <filter type="" />
                      </add>
                  </listeners>
              </trace>
          </system.diagnostics>
          <startup>
              <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
          </startup>
      </configuration>
      

    【讨论】:

    • 我在哪里可以找到这些 dll 引用?我一直在寻找引用这些 dll 的 nuget 包,但我没有找到任何东西。
    • ServiceRuntime 和 Diagnostics 在 Azure SDK 中,而不是在 NuGet 包中。
    • 将 Microsoft.WindowsAzure.Diagnostics 添加到项目中为我修复了它。我通过在VS中右键单击项目的引用文件夹,然后添加引用,然后在Assemblies下的Extensions下找到它来添加它。路径是 C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Microsoft.WindowsAzure.Diagnostics.dll。版本为 2.8.0.0。复制本地为 True。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2019-07-27
    • 2020-04-24
    • 2018-08-28
    • 2019-05-09
    • 1970-01-01
    相关资源
    最近更新 更多