我正在尝试在Silverlight应用程序中使用第三方组件,当我尝试创建控件的实例时,我得到一个XamlParseException:
{System.Windows.Markup.XamlParseException: **Set property 'System.Windows.FrameworkElement.Style' threw an exception.** [Line: 0 Position: 0]
---> System.Windows.Markup.XamlParseException: **Elements in the same ResourceDictionary cannot have the same x:Key** [Line: 1739 Position: 47]
at MS.Internal.XcpImports.CreateFromXaml(UnmanagedMemoryStream stream, String sourceAssemblyName, boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)
at System.Windows.Controls.Control.GetBuiltInStyle(IntPtr nativeTarget, IntPtr& nativeStyle)
--- End of inner exception stack trace ---
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SpellCheckerSample.StandardSpellDialog.InitializeComponent()
at SpellCheckerSample.StandardSpellDialog..ctor()}
Run Code Online (Sandbox Code Playgroud)
我该怎么调试呢?我如何知道位置47所在的文件行1739?
可能有点像找到一个bugger.基本上尝试从调试器中收集尽可能多的细节.
XamlParseException
.在我写完之后,我意识到控件的构造函数确实在callstack上,而且确实如此SpellCheckerSample
.很可能是该控件的.XAML页面.如果您可以访问源,则文件名很可能类似于SpellCheckerSample.xaml.
错误本身非常简单,看起来在同一个ResourceDictionary中使用相同的键定义了多个东西.以下代码将导致这种情况发生:
<Window.Resources>
<myConverters:BananaToCarrotConverter x:Key="StupidestConverterEver" />
<myConverters:BananaToAppleConverter x:Key="StupidestConverterEver" />
<Window.Resources>
Run Code Online (Sandbox Code Playgroud)