none
Custom trace listener class cannot be found via configuration RRS feed

  • Question

  • Hello everyone!

    I have the following problem.

    I created a simple trace listener class, which is derived from ConsoleTraceListener.

    namespace TestUtils

    {

      public class FormattedListener : ConsoleTraceListener

      {

      }

    }


    I added it in to app.config file:

    ...

        <sharedListeners>

    ...

          <add name="formattedListener"

           type="TestUtils.FormattedListener"

           initializeData="formattedOutput.csv"

           traceOutputOptions="DateTime" />

    ...

        </sharedListeners>
    ...

    But when I run the program, it shows error at start: Couldn't find type for class TestUtils.FormattedListener.

     

    The class is included in my executable, and I can create it manually in code. 

    Please tell me what should I do to register the class properly.

     

    Thanks,

    Vlad

     

    Wednesday, October 27, 2010 9:17 PM

Answers

  • Yes, I moved the DLL to EXE location, and now it works!

    Registration in GAC was not necessary. Also the registration spoiled something (maybe I did it wrong), so I unregistered the DLL.


    Thanks
    • Marked as answer by vmikhalyov Thursday, October 28, 2010 8:15 PM
    Thursday, October 28, 2010 8:14 PM

All replies

  • Hi Vlad,

    You probably need to add assembly information to the trace listener type path. For example if your trace listener (TestUtils.FormattedListener) is located in TestUtils.dll assembly, it's configuration should be as follows (I make the missing part bold):

          <add name="formattedListener"

           type="TestUtils.FormattedListener, TestUtils "

           initializeData="formattedOutput.csv"

           traceOutputOptions="DateTime" />

     

    Best,

    Sebastian

    Thursday, October 28, 2010 7:13 AM
  • Hi Sebastian,

    I tried two approaches. Both didn't work.

    1. The listener was in executable. Should I add the main assembly name after comma?

    2. The listener was in a separate assembly (TestUtils.dll). The configuration was as you proposed ("TestUtils.FormattedListener, TestUtils")

    My wild guess is that the tracing logic reads the configuration and tries to find the class in assemblies that are registered in GAC. But it looks too much to me: why I should register assemblies for use in application, which consist of the assemblies?

    Anyway, when I added TestUtils to the GAC, the error didn't go away.

    Thanks,
    Vlad

    Thursday, October 28, 2010 3:14 PM
  • Just some information about my computer:

    Windows 7 64bits

    Visual Studio 2010

     

    I hope it helps


    Thanks
    Thursday, October 28, 2010 3:57 PM
  • Hi Vlad,

    that's very strange. Normally it should be able to load the assembly from the same directory as your exe file. If the listener is in an executable (ad. 1), after the comma you should place the name of this executable but without extension (example: "TestUtils.FormattedListener, ConsoleApplication"). If it's in a separate dll, make sure that this dll is in the same directory as your exe file - you don't need to install it into GAC.

    Best,

    Sebastian

    Thursday, October 28, 2010 4:31 PM
  • Hi Sebastian,

    Maybe the issue was with the DLL being in a different folder. Finally I moved the listener class to the application's assembly, and now it works.

    I'll play later with a separate DLL.

     


    Thanks
    Thursday, October 28, 2010 6:26 PM
  • Yes, I moved the DLL to EXE location, and now it works!

    Registration in GAC was not necessary. Also the registration spoiled something (maybe I did it wrong), so I unregistered the DLL.


    Thanks
    • Marked as answer by vmikhalyov Thursday, October 28, 2010 8:15 PM
    Thursday, October 28, 2010 8:14 PM