微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

silverlight – 如何调试XamlParseException?

我试图在我的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()}

如何调试?我怎么知道什么文件行1739,位置47在?

解决方法

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

>将调试器设置为在XamlParseException上打破.
看看callstack.可能的是,违规控件的构造函数调用堆栈上.
>暂停时,转到“本地调试”窗口,查看该函数的任何参数是否显示了该组件的更多信息.
>如果没有双击下一个堆栈条目并转到步骤3.
>重复步骤3和4.

在我写这个之后,我意识到控件的构造函数确实在调用堆栈上,它是SpellCheckerSample.很可能是该控件的.XAML页面.如果您可以访问源代码,则文件名很可能是类似于SpellCheckerSample.xaml的文件.

错误本身很简单,看起来像在同一个ResourceDictionary中用同一个键定义的多个东西.以下代码将导致这种情况发生:

<Window.Resources>
  <myConverters:BananaToCarrotConverter x:Key="StupidestConverterEver" />
  <myConverters:BananaToAppleConverter x:Key="StupidestConverterEver" />
<Window.Resources>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐