Search code examples
enterprise-library

Enterprise Library CustomTraceListner using Assembly.LoadFrom


So I have created a custom trace listener that inherits from the Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.CustomTraceListener.

The trace listener is a utility dll and the utility dll is reading its config file from utility.dll.config.

I am using LogWriterFactory("utility.dll.config") to create the LogWriter.
When I add a direct reference in a console application to my utility.dll then everything works fine.

But if I use Assembly.LoadFrom("utility.dll") then I get the following error:

The type 'Utility.CustomTraceListner, Utility' cannot be resolved.

If I add utility.dll to the GAC then every thing works fine. I can run AppDomain.CurrentDomain.GetAssemblies() on the line right above the logWriterFactory.Create() and see that utility.dll has been loaded.

I can even run AppDomain.CurrentDomain.CreateInstanceFrom("Utility.dll", "Utility.CustomTraceListener") right before calling logWriterFactory.Create() and get an instance without any problems.

We have an internal application that uses Assembly.LoadFrom and we would like each assembly that is loaded to have its own config file / log settings that are separate from the loading application.

Any ideas how to fix this without putting the utility.dll in the GAC?

I know that the utility.dll.config file is correct because it is working fine when the utility assembly is referenced directly.


Solution

  • Wiring into the ResolveEventHandler solved the issue.

    http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx