Problem Using Prism with Silverlight4 & ContextMenu

Topics: Prism v2 - Silverlight 3
May 12, 2010 at 4:11 PM
Edited May 12, 2010 at 4:16 PM

I have a treeview that I was hanging a context menu control from that worked but didn't support commands so I had to use code behind to fire the methods. I noticed that there is a Context Menu now that is part of the Silverlight SDK that does support commanding so I decided to replace the one I am using for the one in the SDK. Now when I fire up the application I get this error:

Resolution of the dependency failed, type = "ListUI.ListView", name = "". Exception message is: The current build operation (build key Build Key[ListUI.ListView, null]) failed: The attachable property 'ContextMenu' was not found in type 'ContextMenuService'. [Line: 47 Position: 64] (Strategy type BuildPlanStrategy, index 3)

If I dig deeper to the inner exception I also see this message which probably is the root cause of the error

{Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[ListUI.ListView, null]) failed: The attachable property 'ContextMenu' was not found in type 'ContextMenuService'. [Line: 47 Position: 64] (Strategy type BuildPlanStrategy, index 3) ---> System.Windows.Markup.XamlParseException: The attachable property 'ContextMenu' was not found in type 'ContextMenuService'. [Line: 47 Position: 64] ---> System.IO.FileLoadException: Could not load file or assembly 'System.Windows.Controls.Input.Toolkit, Version=4.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest. (Exception from HRESULT: 0x80131053)
   at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, SecurityContextSource securityContextSource)
   at System.Reflection.Assembly.Load(Byte[] rawAssembly)
   at MS.Internal.JoltHelper.LoadAssembly(Byte[] buffdata, Assembly& loadedAssembly)
   --- End of inner exception stack trace ---
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at ListUI.ListView.InitializeComponent()
   at ListUI.ListView..ctor(ListViewModel viewmodel)
   at BuildUp_ListUI.ListView(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)
   --- End of inner exception stack trace ---
   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)}

 If I comment out the context menu xaml the program work fine.

May 19, 2010 at 3:37 PM

Hi,

Based on the exception message you are getting you could check if the System.Windows.Controls.Input.Toolkit.dll is loaded with different versions in your application, or your app manifest is specifying a different version than 4.0.5.0. Take into account that without knowing the specific code you are using, and how you are hooking up the TreeView and the ContextMenu reproducing your issue is complicated.

It would be useful if you could provide a small repro sample, or some relevant pieces of code (both XAML and C#), plus the assemblies you are referencing so we can try to reproduce your issue.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman