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

1

5

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.

Shrew answered 21/12, 2011 at 20:21 Comment(0)
S
13

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"

Shrew answered 21/12, 2011 at 20:23 Comment(1)
dude. seriously. thx for posting this. saved me! exactly my symptom. solution fixed my problem!Nary

© 2022 - 2024 — McMap. All rights reserved.