I get a ConfigurationErrorsException exception "Could not find constructor for CustomListener class"

This is due to the custom System.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 does not happen with the default trace listener.

I found this MSDN message, but it ended up not helping.

+4
source share
1 answer

Found - it took a long time.

The key was this part:

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

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

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

+9
source

Source: https://habr.com/ru/post/1387461/


All Articles