Entyerprise Library 5.0 & Windows 2008 deployment issue

Topics: Data Access Application Block, Logging Application Block
Jun 10, 2011 at 2:56 PM
Edited Jun 10, 2011 at 3:05 PM

Hi,

I'm trying to run InstallServices.bat on my windows 2008 box to install Enterprise Library 5.0 but it fails to create Data application block performance counters. I've created a WCF application which uses Enterprise Library(EPL) blocks. This application is deployed in IIS.  I've done a lot of investigation and I can rule out that all my config files are correct and I've proper definition in web.config file. All my code is residing in single project which contains all EPL references. 

 

I'm getting following error, when using LogWriter!

 

Exception occured in EnterpriseLibraryContainer.Current.GetInstance<Database>  ..Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "" ---> 
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", 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.Data.Database,(none) ---> 
System.InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.   
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)
 in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 289   
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 71   
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 112 
  at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlanCreatorPolicy.cs:line 50 
  at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 37  
 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 112  
 at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 511  
 --- End of inner exception stack trace ---   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) 
in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 517   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides)
 in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 485   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) 
in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49   --- End of inner exception stack trace ---  
 at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 57
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]() in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 90   
at EntMRAPService.LogManager..ctor() in C:\Program Files\EntLib50Src\Blocks\Harness\EntMRAPService\EntMRAPService\LogManager.cs:line 33

 

 

Is this error due to failed InstallServices.bat script? or something to do with config files and my code?

I've modified FileConfigurationSource.GetRootedCurrentConfigurationFile to include AppDomain.CurrentDomain.BaseDirectory path value.

 

My code is as follows: please note that I've copied complete code set including duplicate instantiation. This is just to show you that I've explored all combinations.

 

 

_log.Info("initialising the LogManager instance");

                                string completeFileName = string.Empty;
                                string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                                completeFileName = System.IO.Path.Combine(path, "App.config");
                                 _log.Info("complete path is.." + completeFileName);
                                 _log.Info("app domain directory is .." + AppDomain.CurrentDomain.BaseDirectory);
                                _configSource = new FileConfigurationSource(@"C:\Local\Services\EnterPService\App.config");


                                _myContainer = new UnityContainer();
                                UnityContainerConfigurator myConfigureContainer = new UnityContainerConfigurator(_myContainer);
                                EnterpriseLibraryContainer.ConfigureContainer(myConfigureContainer, _configSource);
  try
            {
                 _log.Info("first initislaising database");
                try
                {
                    _db = EnterpriseLibraryContainer.Current.GetInstance();
                }
                catch (Exception ex)
                {
                     _log.Info("Exception occured in EnterpriseLibraryContainer.Current.GetInstance  .." + ex.ToString());
                }
                _db = new AseDatabase("Data Source='10.37.139.30';Port='5000';UID='sa';PWD='';Database='Logging';CS=iso_1");
                 _log.Info("database construction successfull");
                 _log.Info("In LogManager constructor method....");
                // _logWriter = EnterpriseLibraryContainer.Current.GetInstance();

                 _logWriter = _myContainer.Resolve();

                try
                {
                    _logWriter = new LogWriterFactory(_configSource).Create();
                }
                catch (Exception ex)
                {
                     _log.Info("Exception occured in LogWriterFactory using configsource  .." + ex.ToString());

                }
                 _log.Info("initialising EnterpriseLibraryContainer.Current.GetInstance ....");
                _logWriter = EnterpriseLibraryContainer.Current.GetInstance();
            }
            catch (Exception ex)
            {
                 _log.Info("Exception occured in LogManager .." + ex.ToString());
                throw;
            }

Is it mandatory to run InstallServices.bat script successfully before running application?

 

web.config file:

 

 

 <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
             listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
             databaseInstanceName="Ase Database Connection String" writeLogStoredProcName="WriteLog"
             addCategoryStoredProcName="AddCategory" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />

    </listeners>
  
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
          template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
          name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <dataConfiguration defaultDatabase="Ase Database Connection String">
    <providerMappings>
      <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Ase.AseDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
          name="Sybase.Data.AseClient" />
    </providerMappings>
  </dataConfiguration>
  <connectionStrings>
    <add name="Ase Database Connection String" connectionString="xxxxxxxxxxx"
        providerName="Sybase.Data.AseClient" />
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>

 

Thanks in advance,

 

Cheers,

Rama

Jun 13, 2011 at 6:13 AM

Hi,

I just noticed a type that is unfamiliar to me: Microsoft.Practices.EnterpriseLibrary.Data.Ase.AseDatabase. I can't even find it in the documentation. I'm just curious where did you get that type. Anyway, have you tried to test the config using a simple console or windows application? Seems you are tying to use a custom database here. If you want to, I can send you a sample project on how to create a custom database provider.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 13, 2011 at 8:38 AM

Yes, this config works fine when I run in WPF. I've created custom ASE db provider, which works fine. 

Jun 13, 2011 at 2:59 PM

It's working now. I had to make following changes:

 

1. Set the base directory:  Environment.CurrentDirectory = new FileInfo(AppDomain.CurrentDomain.BaseDirectory).Directory.FullName;

2. Update FileConfigurationSource class to append path!

3. Update web.config to include System data providers!

 <system.data>
    <DbProviderFactories>
      <add name="Sybase.Data.AseClient"
     description="Sybase.Data.AseClient" invariant="Sybase.Data.AseClient" type="Microsoft.Practices.EnterpriseLibrary.Data.Ase.AseDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" />
    </DbProviderFactories>
  </system.data>