Activation Error - W2008R2 Windows Service Ent Lib 5 With .NET 4.0 Targeting x64

Topics: Data Access Application Block, Logging Application Block
Aug 31, 2012 at 1:57 AM

The application logs great from a console app with .NET 4 and Ent Lib 5 on Windows 7 x64.

It does not log and creates the error below when deployed as a Windows Service to a Windows 2008 R2 server.

Due to UCMA 3.0 the application has to be built to target platform x64.

It works great as a console app and as a service deployed to W2008R2 when I changed everything to target .NET 3.5 and x64 with EntLib 5.0.

I switched everything to use Ent Lib 4.1 and it works fine in .NET 3.5 and .NET 4.0.

I really wanted to use Ent Lib 5 as I am using it elsewhere without issue.  UCMA does not work with .NET 4.5 and it is not supposed to work with 4.0 but it does.  I am using VS 2012 and don't want to start too far in the past.  Any ideas?

Service cannot be started. Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type LogWriter, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.__default__ (mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (none))
  Resolving parameter "structureHolder" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder structureHolder, Microsoft.Practices.EnterpriseLibrary.Logging...

Sep 1, 2012 at 3:01 AM

A couple of questions: Are you using a database trace listener in your application?  Are you deploying any assemblies to the GAC?  Usually the issue could be with missing configuration or resolving assemblies.  You could try running the Assembly Binding Log Viewer (fuslogvw.exe) to see if any dependencies cannot be resolved.

Randy Levy
Enterprise Library support engineer 

Sep 1, 2012 at 9:34 PM

Yes I am using the data trace listener logging to SQL server.  In fact that is the only trace listener.  No assemblies are installed to the GAC.  

Are you suggesting that .NET 4.0 might be be leaving out assemblies that .NET 3.5 is including?  That would make since since each time I am deploying a clean application to a remote server. 

If I get time I might circle back on this but right now I have to move forward unless I have a compelling reason to use Ent Lib 5.

Sep 4, 2012 at 3:04 PM

The exception is caused because the container (usually Unity) cannot resolve the Database so it really doesn't point to a specific cause.  The issue can be caused by a number of different issues such as:

  • Requested connection string name is not found in the configuration file
  • Having all assemblies in GAC (without assembly resolve configuration)
  • A missing provider factory in machine.config
  • Other dependent assembly resolution issues

Randy Levy
Enterprise Library support engineer