Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio complain about my web.config trace listeners configuration?

In my web.config I have the following settings:

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

which is just the same as in MSDN example here:

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

Yet Visual Studio will underline type attribute inside <filter type="" and when I move mouse there it says the 'type' attribute is not allowed. If I try using IntelliSense to find what is allowed it offers lockItem, lockElements, lockAttributes, lockAllElementsExcept and lockAllAttributesExcept.

Why does Visual Studio not like type inside filter?

like image 480
sharptooth Avatar asked Mar 04 '13 13:03

sharptooth


1 Answers

Visual Studio uses schemas to verify the XML in the config files. In this case it doesn't see a type attribute defined for the filter element in the schema. This is likely just an oversight/bug in the schema as the use of the filter configuration clearly needs it and will not work without it. This isn't specific to Windows Azure at all.

If you open your app.config/web.config file and check the properties window you'll see the Schemas property. These are all the schemas that are being used to validate your configuration file and there are several. The schema of interest here is DotNetConfig.xsd (on my machine it is under C:\Program Files (x86)\Microsoft Visual Studio 11.0\xml\Schemas\1033\DotNetConfig.xsd using VS 2012). If you are familiar with XSD you can crack this open and if you drill down to the element definition (configuration/system.diagnostics/trace/listeners/ListenerElement/filter) you'll see that no type element is indicated. However, if you look at the filter element under shared listeners (configuration/system.diagnostics/sharedListeners/ListenerElement/filter) the attribute type is there and is required.

If you used the config below you won't see the underline in VS because type is expected under filter at the shared listeners section. I'll point out again that the underline here really doesn't matter, it's just VS saying it doesn't think you should put the type attribute under the filter, but it is clearly required if you want to define the filter under the trace listeners and is just a bug in the schema. I wouldn't worry about it.

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

      </sharedListeners>
        <trace>
            <listeners>
              <add name="AzureDiagnostics" />
            </listeners>
        </trace>
    </system.diagnostics>
like image 138
MikeWo Avatar answered Oct 17 '22 05:10

MikeWo