Showing posts with label assembly not copied. Show all posts
Showing posts with label assembly not copied. Show all posts

Tuesday, January 29, 2008

Enterprise library logging & exception handling application blocks

I am creating a tool which automates the build process of our application. I was using the logging & exception handling application blocks from enterprise library. I encountered an interesting problem.

The “Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging” assembly that is used by the exception handling block to log the exception through the “Logging Handler” is not copied over to the main project output directory.

This issue is also discussed in the following URL : http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=18926

My visual studio solution had a GUI project [windows forms], which references a custom helper class library for logging. The custom library has references to the “Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging” assembly with CopyLocal property set to true. When I build the solution the assembly is copied to the output directory of the class library but not to the main GUI project. So when my application tries to log an exception it fails.

As a workaround I added a using statement to one of the classes in the class library.

using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;

I also added a dummy statement in the code.
LoggingExceptionHandler exceptionHandler = null;

Now the assembly is copied to the main GUI project output directory . If I comment out the above code the assembly is not copied to the output directory.

I guess Visual Studio copies the assemblies to the output directory of main project only if they are referred in the code. Another work around is to use the post build event to copy the dll to the output directory.

Sample:

http://cid-0476ca5e9f26e63c.skydrive.live.com/self.aspx/Public/Documents/WindowsApplication3.zip

Saravanan Kanagaraj