Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't find type for class Microsoft.WindowsAzure.Diagnostics

Just got back from holidays, and went in to make a couple small changes in our app, when I was confronted by this error:

Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

The code had been running perfectly prior to coming back from holidays. It was last published to Azure 3 weeks ago, and it is now having the same issue there. Locally I attempted to fix it by removing add adding the following config section back:

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

Add adding and removing the Reference to the assembly:

enter image description here

When I debug the project locally, Visual Studio breaks on the following line:

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

This had been working both locally and in production until 2 days ago (according to the error log).

Full Stack Trace:

[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
like image 989
Jeremy Boyd Avatar asked Jan 07 '14 16:01

Jeremy Boyd


2 Answers

If you aren't running in the emulator, then see my SO answer here - How to solve Windows Azure Diagnostic Runtime Error (Could not create WindowsAzure.Diagnostics, Version=xx, Culture=neutral, PublicKeyToken=xx. Basically, just add:

<filter level="TraceEventType.Error" />

in the <listeners><add> section.

like image 86
viperguynaz Avatar answered Sep 30 '22 03:09

viperguynaz


While I had a project reference to, and local copy of, Microsoft.WindowsAzure.Diagnostics.dll in my Cloud Service Package, it turns out that you also need a copy of MonAgentListener.dll in the package too - after adding that file it started working again.

Specifically, I'm using Microsoft.WindowsAzure.Diagnostics.dll version 2.8.0.0, it is 35,608 bytes (34.7KB) in size. It is the same file as C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Microsoft.WindowsAzure.Diagnostics.dll.

And MonAgentListener.dll version 33.1.5.0, 74,448 bytes (72.7KB) in size, and it is the same file as C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\MonAgentListener.dll.

Do not confuse this 35KB version of Microsoft.WindowsAzure.Diagnostics.dll with the 311KB version at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Windows Azure Tools Diagnostics 1.0\Microsoft.WindowsAzure.Diagnostics.dll or C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Windows Azure Tools\v2.9\Microsoft.WindowsAzure.Diagnostics.dll which are both marked as version 2.4.6489.4.

My project is using the Azure PaaSDiagnostics extension (which is what the Azure PowerShell and Azure Portal use) instead of the Microsoft.WindowsAzure.Plugins.Diagnostics plugin which is an older version of Cloud Service diagnostics (which uses the now obsolete "plugin" model instead of the current "extension" model). Given that Extensions are meant to work against any Cloud Service - it turns out you still need to reference these assemblies and include them in your package - the extension will not do it for you.

But to make things more confusing: If you have a VS Cloud Service project then Visual Studio 2015 and even Visual Studio 2017 still use the older plugin system if you use VS's Cloud Project deployment system.

(Given that the "Cloud Service" system is legacy and only supported by the older Azure "Service Management" API and is not supported by the current-generation "Resource Management" API and system it's not surprising that MS hasn't invested in improving the tooling for Cloud Services in Visual Studio - but this confusion between the Plugins vs. Extensions (for both Diagnostics and Remote Desktop) delayed my project by weeks while I researched what I should be doing.

Also ensure that your Cloud Service's reference to Microsoft.WindowsAzure.ServiceRuntime.dll has Copy Local = True set. This will also copy the files WindowsAzureEventSource.dll and WindowsAzureTelemetryEvents.dll to your output - and ensure all 3 files are included in your Cloud Service Package.

TL;DR:

  1. Ensure you have these files in your Cloud Service package file (so they're deployed to E:\approot when deployed)

    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. Also ensure your Cloud Service Worker Role project has an App.config file with this:

    <?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>
    
like image 20
Dai Avatar answered Sep 30 '22 03:09

Dai