Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 227
MatthewMartin Avatar asked Dec 21 '11 20:12

MatthewMartin


1 Answers

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"

like image 173
MatthewMartin Avatar answered Sep 28 '22 17:09

MatthewMartin