I'm getting an ConfigurationErrorsException “Couldn't find constructor for class CustomListener”

StackOverflow https://stackoverflow.com/questions/8595845

  •  24-03-2021
  •  | 
  •  

Question

This is related to custom a Systems.Diagnostics.TraceListener

<system.diagnostics>
    <sources>
        <source name="SomeTraceSourceName" 
            switchType="System.Diagnostics.SourceSwitch" 
            switchName="SomeSwitchName">
            <listeners>
                <clear />
                <add name="CustomListener"/>
            </listeners>
        </source>
    </sources>
    <sharedListeners>
        <add name="CustomListener"
            type="CustomListener, MyAssembly" 
            initializeData=""/>
    </sharedListeners>
    <switches>
        <add name="SomeSwitchName" value="4"  />
    </switches>
</system.diagnostics>

This doesn't happen with the default trace listener.

I found this MSDN post, but ultimately, it didn't prove helpful.

Was it helpful?

Solution

Found it-- it took a long time.

The key was this part:

<add name="CustomListener"
            type="CustomListener, MyAssembly" 
            initializeData=""/>

When the intializationData is a blank string, it will look for a constructor with no arguments. As soon as I added the value for initializeData then the framework found the constructor.

The error should have said "No constructor with 0 parameters, maybe you need to include some initializeData"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top