InjectionConstructor not able to resolve parameter

Jan 21, 2010 at 10:02 PM

I have the following Unity configuration in the <container><types> section:

<type type="gisPlugIface" mapTo="googleEarthGISPlugin" name="google">
            <lifetime type="singleton" />
            <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
              <constructor>
                <param name="manufacturer" parameterType="System.String">
                  <value value="Google"/>
                </param>
                <param name="productName" parameterType="System.String">
                  <value value="Earth"/>
                </param>
                <param name="isActiveEngine" parameterType="System.Boolean">
                  <value value="true"/>
                </param>
              </constructor>
            </typeConfig>
          </type>

When I try to resolve this object instance, I get the following exception:

Microsoft.Practices.Unity.ResolutionFailedException was unhandled
  Message="Resolution of the dependency failed, type = \"OCC600.Infrastructure.Interface.Plugins.GIS.IGISModuleController\", name = \"google\". Exception message is: The current build operation (build key Build Key[OCC600.GoogleEarthLibrary.Models.ModuleController, google]) failed: The parameter isActiveEngine could not be resolved when attempting to call constructor OCC600.GoogleEarthLibrary.Models.ModuleController(System.String manufacturer, System.String productName, System.Boolean isActiveEngine). (Strategy type BuildPlanStrategy, index 3)"
  Source="Microsoft.Practices.Unity"
  NameRequested="google"
  TypeRequested="IGISModuleController"
  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.UnityContainer.<ResolveAll>d__4.MoveNext()
       at Microsoft.Practices.Unity.UnityContainerBase.<ResolveAll>d__0`1.MoveNext()
       at MS.Internal.Data.EnumerableCollectionView.LoadSnapshotCore(IEnumerable source)
       at MS.Internal.Data.EnumerableCollectionView..ctor(IEnumerable source)
       at MS.Internal.Data.ViewManager.GetViewRecord(Object collection, CollectionViewSource cvs, Type collectionViewType, Boolean createView)
       at MS.Internal.Data.DataBindEngine.GetViewRecord(Object collection, CollectionViewSource key, Type collectionViewType, Boolean createView)
       at System.Windows.Data.CollectionViewSource.GetDefaultCollectionView(Object source, Boolean createView)
       at System.Windows.Data.CollectionViewSource.GetDefaultCollectionView(Object source, DependencyObject d)
       at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)
       at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable value)
       at ControlsLibrary.wpf.GIS.MapView..ctor(PresenterBase presenter) in C:\dev\LUT600 2.1.1\OCC600\Source\Libraries\ControlsLibrary\wpf\GIS\MapView.xaml.cs:line 30
       at TestingControls.Window1..ctor(IUnityContainer container) in C:\dev\LUT600 2.1.1\OCC600\Source\Libraries\GIS\TestingControls\Window1.xaml.cs:line 59
       at TestingControls.Bootstrapper.CreateShell() in C:\dev\LUT600 2.1.1\OCC600\Source\Libraries\GIS\TestingControls\Bootstrapper.cs:line 51
       at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run(Boolean useDefaultConfiguration)
       at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run()
       at TestingControls.App..ctor() in C:\dev\LUT600 2.1.1\OCC600\Source\Libraries\GIS\TestingControls\App.xaml.cs:line 18
       at TestingControls.App.Main() in C:\dev\LUT600 2.1.1\OCC600\Source\Libraries\GIS\TestingControls\obj\Alone\App.g.cs:line 47
       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
       Message="The current build operation (build key Build Key[OCC600.GoogleEarthLibrary.Models.ModuleController, google]) failed: The parameter isActiveEngine could not be resolved when attempting to call constructor OCC600.GoogleEarthLibrary.Models.ModuleController(System.String manufacturer, System.String productName, System.Boolean isActiveEngine). (Strategy type BuildPlanStrategy, index 3)"
       Source="Microsoft.Practices.ObjectBuilder2"
       BuildKey="Build Key[OCC600.GoogleEarthLibrary.Models.ModuleController, google]"
       ExecutingStrategyIndex=3
       ExecutingStrategyTypeName="BuildPlanStrategy"
       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 isActiveEngine could not be resolved when attempting to call constructor OCC600.GoogleEarthLibrary.Models.ModuleController(System.String manufacturer, System.String productName, System.Boolean isActiveEngine)."
            Source="Microsoft.Practices.ObjectBuilder2"
            StackTrace:
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForResolutionFailed(Exception inner, String parameterName, String constructorSignature, IBuilderContext context)
                 at BuildUp_OCC600.GoogleEarthLibrary.Models.ModuleController(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: System.InvalidCastException
                 Message="Specified cast is not valid."
                 Source="EMS.OCC600.GoogleEarthLibrary"
                 StackTrace:
                      at BuildUp_OCC600.GoogleEarthLibrary.Models.ModuleController(IBuilderContext )
                 InnerException:

 

If I remove the bool constructor parameter or make it a string, all is well.    I suspect there is something wrong with my config but I cannot see it.  Can someone help?

TIA.

 

Jan 21, 2010 at 11:11 PM

You need to give the type for both the parameter AND the value. Otherwise the config assumes it's a string value you're trying to assign to a bool and it gets upset.

add type="System.Boolean" to the <value> tag and it should work.

 

Jan 22, 2010 at 3:28 PM

Thanks.  Someone missed that when browsing through the doc.

Jan 23, 2010 at 1:24 AM

Yeah, it's annoying. You won't need to do it with Unity 2.0.