Error injecting LogWriter

Jan 8, 2010 at 6:10 AM

 

Hi All,
I have a Windows Forms application which perform CRUD operations to a database. Nothing fancy, very simple. To enable logging, i am using Logging Application block in conjunction with Unity.
I have a class named ServiceLocator.vb, which initializes the container with the dependent objects. I have two client objects, Form1.vb and Form2.vb that act as user interfaces. Everything worked as i expected.
 
I eventually had to convert my Form1.vb and Form2.vb into two Windows Service components, where the user interface is replaced with other form of input.
So, this is what i did. I put the forms into two independent windows service projects.
To the Windows service projects i included Core (which is my original project) as a reference.
When i try to run this, i get errors that i cant seem to understand. the details are below.
 
Dim batch As Batch = Core.ServiceLocator.Container.Resolve(Of IData)(Constants.BATCH)
Error i get here is -
Resolution of the dependency failed, type = "Core.IData", name = "BATCH". Exception message is: The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)
 
I believe i am missing something very basic. Could someone please highlight?
 
thanks, Hari.

Hi All,

I have a Windows Forms application which perform CRUD operations to a database. Nothing fancy, very simple. To enable logging, i am using Logging Application block in conjunction with Unity.

I have a class named ServiceLocator.vb, which initializes the container with the dependent objects. I have two client objects, Form1.vb and Form2.vb that act as user interfaces. Everything worked as i expected.

I eventually had to convert my Form1.vb and Form2.vb into two Windows Service components, where the user interface is replaced with other form of input.

So, this is what i did. I put the forms into two independent windows service projects.

To the Windows service projects i included Core (which is my original project) as a reference.

When i try to run this, i get errors that i cant seem to understand. the details are below.

Dim batch As Batch = Core.ServiceLocator.Container.Resolve(Of IData)(Constants.BATCH)

Error i get here is -

Resolution of the dependency failed, type = "Core.IData", name = "BATCH". Exception message is: The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)

I believe i am missing something very basic. Could someone please highlight?

thanks, Hari.

 

Jan 8, 2010 at 7:47 AM

Typically with Unity 1.2 & earlier, the real error is buried further down in the error message. If you could post the entire exception message & stack track, I can probably figure out what's happening pretty quickly.

 

Jan 11, 2010 at 2:30 PM

hey, thanks for the post. here is the detail

 

 

Microsoft.Practices.Unity.ResolutionFailedException was unhandled
  Message="Resolution of the dependency failed, type = "Core.IData", name = "BATCH". Exception message is: The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)"
  NameRequested="BATCH"
  Source="Microsoft.Practices.Unity"
  TypeRequested="IData"
  StackTrace:
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)
       at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)
       at Microsoft.Practices.Unity.UnityContainerBase.Resolve[T](String name)
       at TestingApp.Form1.Form1_Load(Object sender, EventArgs e) in D:\Ithos-Files\Projects\Content_ingestion_system\TestingApp\Clients\Form1.vb:line 48
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at TestingApp.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException
       BuildKey="Build Key[Core.Batch, BATCH]"
       ExecutingStrategyIndex=3
       ExecutingStrategyTypeName="BuildPlanStrategy"
       Message="The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)"
       Source="Microsoft.Practices.ObjectBuilder2"
       StackTrace:
            at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
            at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)
            at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
       InnerException: System.InvalidOperationException
            Message="The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter)."
            Source="Microsoft.Practices.ObjectBuilder2"
            StackTrace:
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)
                 at BuildUp_Core.Batch(IBuilderContext )
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
                 at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
            InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException
                 BuildKey="Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]"
                 ExecutingStrategyIndex=3
                 ExecutingStrategyTypeName="BuildPlanStrategy"
                 Message="The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]) failed: The parameter filters could not be resolved when attempting to call constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation). (Strategy type BuildPlanStrategy, index 3)"
                 Source="Microsoft.Practices.ObjectBuilder2"
                 StackTrace:
                      at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                      at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)
                      at BuildUp_Core.Batch(IBuilderContext )
                 InnerException: System.InvalidOperationException
                      Message="The parameter filters could not be resolved when attempting to call constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation)."
                      Source="Microsoft.Practices.ObjectBuilder2"
                      StackTrace:
                           at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)
                           at BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(IBuilderContext )
                           at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
                           at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
                           at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                      InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException
                           BuildKey="Build Key[System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], null]"
                           ExecutingStrategyIndex=3
                           ExecutingStrategyTypeName="BuildPlanStrategy"
                           Message="The current build operation (build key Build Key[System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], null]) failed: The current type, System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3)"
                           Source="Microsoft.Practices.ObjectBuilder2"
                           StackTrace:
                                at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                                at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)
                                at BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(IBuilderContext )
                           InnerException: System.InvalidOperationException
                                Message="The current type, System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], is an interface and cannot be constructed. Are you missing a type mapping?"
                                Source="Microsoft.Practices.ObjectBuilder2"
                                StackTrace:
                                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context)
                                     at BuildUp_System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](IBuilderContext )
                                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
                                     at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
                                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
                                InnerException: 

Microsoft.Practices.Unity.ResolutionFailedException was unhandled

  Message="Resolution of the dependency failed, type = "Core.IData", name = "BATCH". Exception message is: The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)"

  NameRequested="BATCH"

  Source="Microsoft.Practices.Unity"

  TypeRequested="IData"

  StackTrace:

       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)

       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)

       at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)

       at Microsoft.Practices.Unity.UnityContainerBase.Resolve[T](String name)

       at TestingApp.Form1.Form1_Load(Object sender, EventArgs e) in D:\Ithos-Files\Projects\Content_ingestion_system\TestingApp\Clients\Form1.vb:line 48

       at System.EventHandler.Invoke(Object sender, EventArgs e)

       at System.Windows.Forms.Form.OnLoad(EventArgs e)

       at System.Windows.Forms.Form.OnCreateControl()

       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

       at System.Windows.Forms.Control.CreateControl()

       at System.Windows.Forms.Control.WmShowWindow(Message& m)

       at System.Windows.Forms.Control.WndProc(Message& m)

       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

       at System.Windows.Forms.ContainerControl.WndProc(Message& m)

       at System.Windows.Forms.Form.WmShowWindow(Message& m)

       at System.Windows.Forms.Form.WndProc(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)

       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)

       at System.Windows.Forms.Control.set_Visible(Boolean value)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.Run(ApplicationContext context)

       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)

       at TestingApp.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException

       BuildKey="Build Key[Core.Batch, BATCH]"

       ExecutingStrategyIndex=3

       ExecutingStrategyTypeName="BuildPlanStrategy"

       Message="The current build operation (build key Build Key[Core.Batch, BATCH]) failed: The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter). (Strategy type BuildPlanStrategy, index 3)"

       Source="Microsoft.Practices.ObjectBuilder2"

       StackTrace:

            at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

            at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)

            at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)

       InnerException: System.InvalidOperationException

            Message="The parameter logWriter could not be resolved when attempting to call constructor Core.Batch(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter logWriter)."

            Source="Microsoft.Practices.ObjectBuilder2"

            StackTrace:

                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)

                 at BuildUp_Core.Batch(IBuilderContext )

                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)

                 at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

            InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException

                 BuildKey="Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]"

                 ExecutingStrategyIndex=3

                 ExecutingStrategyTypeName="BuildPlanStrategy"

                 Message="The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]) failed: The parameter filters could not be resolved when attempting to call constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation). (Strategy type BuildPlanStrategy, index 3)"

                 Source="Microsoft.Practices.ObjectBuilder2"

                 StackTrace:

                      at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                      at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)

                      at BuildUp_Core.Batch(IBuilderContext )

                 InnerException: System.InvalidOperationException

                      Message="The parameter filters could not be resolved when attempting to call constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation)."

                      Source="Microsoft.Practices.ObjectBuilder2"

                      StackTrace:

                           at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)

                           at BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(IBuilderContext )

                           at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)

                           at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

                           at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                      InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException

                           BuildKey="Build Key[System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], null]"

                           ExecutingStrategyIndex=3

                           ExecutingStrategyTypeName="BuildPlanStrategy"

                           Message="The current build operation (build key Build Key[System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], null]) failed: The current type, System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3)"

                           Source="Microsoft.Practices.ObjectBuilder2"

                           StackTrace:

                                at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                                at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context)

                                at BuildUp_Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter(IBuilderContext )

                           InnerException: System.InvalidOperationException

                                Message="The current type, System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], is an interface and cannot be constructed. Are you missing a type mapping?"

                                Source="Microsoft.Practices.ObjectBuilder2"

                                StackTrace:

                                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context)

                                     at BuildUp_System.Collections.Generic.ICollection`1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](IBuilderContext )

                                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)

                                     at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

                                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                                InnerException: 

 

Jan 12, 2010 at 5:51 AM

My initial guess based on the fundamental cause, which is here:

                           Message="The current build operation (build key Build Key[System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], null]) failed: The current type, System.Collections.Generic.ICollection`1[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter], is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3)"

is that the container isn't configured with the right Enterprise Library extensions to properly resolve a LogWriter. Either that, or it's not finding the correct config file.

Does you app work if you get LogWriter objects directly through a LogWriterFactory? That'd be a quick way to tell if it's finding the right config file or not.

Jan 12, 2010 at 8:17 AM

Hey, thanks for taking the time.

As i mentioned initially, when i have my client components (form1.vb and form2.vb) in the same application as the rest of the business logic components that use Enterprise Libraries, it indeed works. The issue arises when i extract the forms into a separate project. 

Once i moved the form into a separate project this is what i did

Dim batch As Batch = Core.ServiceLocator.Container.Resolve(Of IData)(Constants.BATCH)

Core is the name of Class library.

when you say 'finding the config file' - which project should host the config file? The client tool or the class library?

Jan 12, 2010 at 4:39 PM

The config file must be the one for the executable - libraries don't get config files.

 

 

Jan 13, 2010 at 9:19 AM

Hi there,

Thanks for the tip. It worked like a charm. Your're help is unparalleled.

In hindsight, this may look obvious, but i surely didnt figure it. Thanks again.

cheers, Hari