Exception when calling EnterpriseLibraryContainer.Current.GetInstance(Of ExceptionManager)()

Oct 20, 2011 at 1:12 PM

Hello,

I am continually getting an exception when calling a simple instruction:
Dim exManager As ExceptionManager = EnterpriseLibraryContainer.Current.GetInstance(Of ExceptionManager)()

I am using the recent version v5 of enterprise library, downloaded recently. I have looked at various other threads in codeplex where users have encountered similar error and it states that this issue was deep rooted somewhere within the library and the status is now closed (http://unity.codeplex.com/workitem/7019?ProjectName=unity). I am not able to get through this piece of line which I am using just to create a usable instance of ExceptionManager class to handle my exception. My application is waiting to get across this thorny ride just to log the exception and proceed for further actions. In case v5 of enterprise library does not have a patch to overcome it, I have to abandon enterprise library [unfortunately !! :-( ] and look for an alternative application block to overcome the issue, I am working under strict deadline and business wont wait for long. Do let me know if atleast a patch is available

The complete stack trace reads as below:

System.ArgumentException was caught
  Message=The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.
  Source=Microsoft.Practices.EnterpriseLibrary.Common
  StackTrace:
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.AssemblyQualifiedTypeNameConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\AssemblyQualifiedTypeNameConverter.cs:line 63
       at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement.get_Type() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\NameTypeConfigurationElement.cs:line 58
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.CustomHandlerData.<GetRegistrations>d__1.MoveNext() in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\Configuration\CustomHandlerData.cs:line 208
       at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
       at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
       at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\ExceptionHandling\Src\ExceptionHandling\Configuration\ExceptionHandlingSettings.cs:line 96
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider p, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationsAccessor) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 88
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ConfigSectionLocator.cs:line 60
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider l, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 128
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 147
       at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\Unity\UnityContainerConfigurator.cs:line 61
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ChangeTrackingContainerConfigurator.cs:line 66
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 83
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 62
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 122
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 108
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 95
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 36
       at Foundation.ExceptionHandler.HandleException(ApplicationException ex, String policyName) in D:\Tasks\Working\Fleet\Foundation\ExceptionHandler.vb:line 65
  InnerException:

Oct 21, 2011 at 10:46 AM

Hi,

The item you link to is a different issue -- that issue is a first chance exception Lock Synchronization Exception being thrown and handled by Enterprise Library when debugging.  It makes it a pain to debug.

I think what you are seeing is that you haven't added a reference to Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll.

Oct 21, 2011 at 10:54 AM

All the references already exist in my project including the reference to 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll.'

I had cross-checked a few sites where they asked to add the similar reference, but the reference to the dll already existed in my project. Still, for a try, I removed the reference and added it back again and ran the application; it gave the same error. Is any problem in the config file which may be used internally by the dll, repeatedly reading the config file do not show any config error.

Oct 22, 2011 at 7:18 AM

Can you post your config file?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Oct 24, 2011 at 9:27 AM

Hi,

Attached find the requested config file which is being used.

How I am forcefully raising an exception is by setting a wrong userid/pwd in the connection string. This will cause an exception to be raised when the application tries to connect to the DB and this exception is expected to be logged.

Also attached find screen shot showing the references that are added to the application to log the exception and the line in code that causes the specific exception to be raised when invoked.

Thanks & Regards,

Melwin


Atos and Atos Consulting are trading names used by the Atos group. The following trading entities are registered in England and Wales: Atos IT Services UK Limited (registered number 01245534), Atos Consulting Limited (registered number 04312380) and Atos IT Solutions and Services Limited (registered number 01203466) The registered office for each is at 4 Triton Square, Regents Place, London, NW1 3HG.The VAT No. for each is: GB232327983

This e-mail and the documents attached are confidential and intended solely for the addressee, and may contain confidential or privileged information. If you receive this e-mail in error, you are not authorised to copy, disclose, use or retain it. Please notify the sender immediately and delete this email from your systems. As emails may be intercepted, amended or lost, they are not secure. Atos therefore can accept no liability for any errors or their content. Although Atos endeavours to maintain a virus-free network, we do not warrant that this transmission is virus-free and can accept no liability for any damages resulting from any virus transmitted. The risks are deemed to be accepted by everyone who communicates with Atos by email.

Oct 25, 2011 at 6:43 AM

Hi Melwin,

I don't see the screen shot in your post.  Can you post your config file? It would be helpful.

Thanks,

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Oct 25, 2011 at 11:06 AM

Below is the config file entry:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="DAL">
    <listeners>
      <add name="EventLogListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Text Formatter"
        log="" machineName="." traceOutputOptions="None" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        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="DAL">
        <listeners>
          <add name="EventLogListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="EventLogListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="DALPolicy">
        <exceptionTypes>
          <add name="DALException" type="DAL.DALException, DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="DAL Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="DAL" eventId="9999" severity="Critical" title="DAL Exception Handler"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  <connectionStrings>
    <add name="FleetAlert" connectionString="Data Source=xxxxxxxxxxx"
      providerName="Oracle.DataAccess" />
  </connectionStrings>
  <appSettings>
    <add key="RefreshInterval" value="1" />
    <add key="DemoUnit" value="LA61" />
    <add key="DALPolicy" value="DALPolicy" />
  </appSettings>
</configuration>

Oct 26, 2011 at 4:21 AM

The config looks fine.  I keep coming back to the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler reference.

Now it may not be a reference per se since the code does not need that reference to compile the DLL just needs to be resolvable at runtime.  Since the reference has been added, is CopyLocal set to true?  Is the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.dll in the output (or deployment) folder?

It may be easier to email me a small project that reproduces the issue.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Oct 27, 2011 at 10:52 AM

Hello Randy,

Attached find the new project that I created to mimic my original application. It returns the same error as the original one.

Hope it will help

Thanks & Regards,

cid:image001.gif@01CC3101.E6169630

Melwin M. Nadar

From: randylevy [email removed]
Sent: 26 October 2011 05:22
To: Nadar, Melwin
Subject: Re: Exception when calling EnterpriseLibraryContainer.Current.GetInstance(Of ExceptionManager)() [unity:276574]

From: randylevy

The config looks fine. I keep coming back to the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler reference.

Now it may not be a reference per se since the code does not need that reference to compile the DLL just needs to be resolvable at runtime. Since the reference has been added, is CopyLocal set to true? Is the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.dll in the output (or deployment) folder?

It may be easier to email me a small project that reproduces the issue.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com


Atos and Atos Consulting are trading names used by the Atos group. The following trading entities are registered in England and Wales: Atos IT Services UK Limited (registered number 01245534), Atos Consulting Limited (registered number 04312380) and Atos IT Solutions and Services Limited (registered number 01203466) The registered office for each is at 4 Triton Square, Regents Place, London, NW1 3HG.The VAT No. for each is: GB232327983

This e-mail and the documents attached are confidential and intended solely for the addressee, and may contain confidential or privileged information. If you receive this e-mail in error, you are not authorised to copy, disclose, use or retain it. Please notify the sender immediately and delete this email from your systems. As emails may be intercepted, amended or lost, they are not secure. Atos therefore can accept no liability for any errors or their content. Although Atos endeavours to maintain a virus-free network, we do not warrant that this transmission is virus-free and can accept no liability for any damages resulting from any virus transmitted. The risks are deemed to be accepted by everyone who communicates with Atos by email.

Oct 28, 2011 at 12:59 AM

Thanks for the project.  As I suspected, the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll and Microsoft.Practices.EnterpriseLibrary.Logging.dll are not being copied to your output directory.  It looks like even though a reference is added to the DAL project it recognizes that those assemblies are not used.

You can add a post build command to copy those assemblies or if you just use any of the objects in the assemblies (imports doesn't count) then the assemblies will be copied.  E.g.

Public Class DALBase

    Private exManager As ExceptionManager = EnterpriseLibraryContainer.Current.GetInstance(Of ExceptionManager)()
    Private exLogging As Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler
    Private logWriter As Microsoft.Practices.EnterpriseLibrary.Logging.Logger

...

End Class

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Oct 28, 2011 at 11:08 AM

Perfect!!! Indeed the application wasnt copying the 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll' to the target directory. I added a post-built command and there it  goes, it ran well and the first log file with expected exception was written on the correct location. Thanks randy for the solution, I would have had to abandon the EL in case a solution wouldnt have been found. Thanks again, it has made my day :-)