ConfigurationSourceBuilder error?

Topics: Enterprise Library Core, Logging Application Block
Mar 19, 2013 at 12:11 PM
I am trying to get instance of LogWriter using ConfigurationSourceBuilder (i cant use config file in this case). LogWriter is created in helper class that is used by other assemblies to create logger. In this case LogWriter its used in mscrm 4 customworkflow but sometimes i am getting exception:
Workflow paused due to error: Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.  at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)  at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)  at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)  at System.Type.GetType(String typeName)  at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.AddValidationExtension()  at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer container)  at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource)  at Talon.Hp.Crm.CrossCutting.UContainer.GetLog()  at Talon.Hp.Crm.Workflows.SendSagePayReceiptActivity.Execute(ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)  at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)  at System.Workflow.Runtime.Scheduler.Run().
After that i need to restart windows service because it stops working at all. I updated EntLib to the latest version but still same problem.

               if (log == null)
                    log = container.Resolve<LogWriter>();
                catch (Exception)
                    var builder = new ConfigurationSourceBuilder();
                                .FormatWith(new FormatterBuilder()
                                 .TextFormatterNamed("Text Formatter")
                                   .UsingTemplate("Title: {title}{newline}Timestamp: {timestamp}{newline}Category: {category}{newline}" +
                                                  "Message: {message} {newline}"))

                    var configSource = new DictionaryConfigurationSource();
                    var cont = EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
                    log = cont.GetInstance<LogWriter>();
Any idea what can cause that exception?
Mar 20, 2013 at 3:58 AM
Edited May 1, 2013 at 8:35 PM
The code itself looks OK so it looks like it's related to the environment or configuration.

The error is happening trying to get the type for Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Unity.ValidationBlockExtension, Microsoft.Practices.EnterpriseLibrary.Validation. There is a soft dependency in there and if the type cannot be found it just skips adding the validation extension.

Since you are using CRM I'm assuming that you have deployed to the GAC. Is Microsoft.Practices.EnterpriseLibrary.Validation.dll deployed in the GAC?

If so, you could try adding the following to the configuration:
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Validation" fullName="Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Randy Levy
Enterprise Library support engineer
Support How-to
Mar 21, 2013 at 8:08 AM

Thanks for the reply. The problem is that i cant really update the CRM web.config (unsuported customisation). I changed this from running async to sync and this fixed the problem. I do not know what was causing it but it just did not want to work async.