你如何调试XamlParseException?

Cra*_*rer 14 silverlight xaml

我正在尝试在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?

Igo*_*aka 7

可能有点像找到一个bugger.基本上尝试从调试器中收集尽可能多的细节.

  1. 将调试器设置为中断XamlParseException.
  2. 看看callstack.有问题的控件的构造函数可能在callstack上.
  3. 暂停时,转到Locals调试窗口,查看函数的任何参数是否显示更多关于这个组件的信息.
  4. 如果没有双击下一个堆栈条目,请转到步骤3.
  5. 重复步骤3和4.

在我写完之后,我意识到控件的构造函数确实在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)


Cra*_*rer 2

结果我的具体问题是 ComponentOne 组件只能在 Silverlight 4 下工作。一旦我更改为目标 SL4,一切都可以工作。