Last post Jul 10, 2009 11:01 PM by DalePres
Jul 07, 2009 01:08 PM|DalePres|LINK
I have a custom trace listener in my app_config folder. I add the trace listener to the app in the web.config. (I tried to paste the code but there's no good code handing on these forums and it totally messes it up when I paste it.)
The application runs fine until my first call to System.Diagnostics.Trace when I get this error:
Couldn't find type for class Sample.Diagnostics.ErrorLoggingTraceListener.
I'm sure the code in web.config is correct and I'm sure the class and namespace are correct. I have used the same code in .Net 1.1 apps for web.config and in many WinForms apps in app.config. I can add the TraceListener in codebehind; I just can't add
it in 2.0 web.config.
I am fairly sure that this comes from the multiple DLLs that asp.net 2.0 projects compile into so the code that parses the web.config is in a different assembly than the code that holds the TraceListener. I can't specify the assembly name for the TraceListener
because that name is random and may not be the same from build to build.
I think this is a bug in asp.net because all classes in web_config should be referenced to the rest of the app and that is not happening in the case of a declarative addition of a TraceListener.
Any ideas on how to make this work?
Jul 08, 2009 12:57 AM|shnaraya|LINK
Can you post your web config code.
Do you have something like this
You should specify the name of assembly after the comma. Morover right click ther properties for your custom listener project, check that assembly name is same as defined in the webconfig. Also add reference to the assemly to your web project.
Jul 10, 2009 11:01 PM|DalePres|LINK
You're referring to a fully qualified type name. That is exactly the point of my question. In ASP.Net 2.0 and later, with sites compiled into multiple DLLs or in websites instead of web projects, you cannot predict what the assembly name will be at design
time so you can't include it to create the fully qualified type name.
I am at home and can't get to the code but it is basically:
<add name="ErrorLoggingTraceListener", type="Sample.Diagnostics.ErrorLoggingTraceListener" />
But changing to
<add name="ErrorLoggingTraceListener", type="Sample.Diagnostics.ErrorLoggingTraceListener, MyAssemblyName" />
won't help because I have no way of knowing what "MyAssemblyName" is. This highlights one of the problems with the whole idea of multiple dlls in a web site. It would work if the TraceListener loader would search all loaded assemblies before failing.
I finally settled on using a separate DLL for my trace listener. By putting it in a separate library instead of in the app_code folder in the website, the assembly name becomes known and I can use the fully qualified type name.
Thanks for the help.