Search code examples
c#wpf

c#/wpf ResourceDictionary.DeferrableContent exception


Hi I have an c#/wpf application with a set of UserControls and got an error when starting debugging in visual studio 2015 when showing a specific UserControl(both in debug and release settings):

Additional information: 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.' Line number '16' and line position '6'.

Line 16 in the xaml file of the UserControlthat causes the exception to be thrown is:

<UserControl.Resources>

The _innerException of the thrown exception states:

{"Item has already been added. Key in dictionary: 'System.Windows.Controls.StackPanel' Key being added: 'System.Windows.Controls.StackPanel'"}

This seems quite strange and I do not know how to tackle this. I have googled for any clues but they are mostly relevant for specific plugins like telerik and such. Many solutions I have found seems rather "accidental".

Does anyone have any ideas?

(using visual studio 2015)


Solution

  • I found I had two "keyless" <style></style> tags in the <UserControl.Resources> that caused the problem. Merging these corrected the error. (too bad visual studio does not highlight this as a problem)