Silverlight 如何调试XamlParseException?
我尝试在Silverlight应用程序中使用第三方组件,当我尝试创建控件实例时,我得到一个XamlParseException:Silverlight 如何调试XamlParseException?,silverlight,xaml,Silverlight,Xaml,我尝试在Silverlight应用程序中使用第三方组件,当我尝试创建控件实例时,我得到一个XamlParseException: {System.Windows.Markup.XamlParseException: **Set property 'System.Windows.FrameworkElement.Style' threw an exception.** [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseExc
{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位是什么文件?可能有点麻烦。基本上,尝试从调试器收集尽可能多的细节
XamlParseException
上中断SpellCheckerSample
。很可能是该控件的.XAML页面。如果可以访问源文件,则文件名很可能类似于SpellCheckerSample.xaml
错误本身非常简单,看起来在同一个ResourceDictionary中使用同一个键定义了多个内容。以下代码将导致发生这种情况:
<Window.Resources>
<myConverters:BananaToCarrotConverter x:Key="StupidestConverterEver" />
<myConverters:BananaToAppleConverter x:Key="StupidestConverterEver" />
<Window.Resources>
我的具体问题是ComponentOne组件只能在Silverlight 4下工作。一旦我改为目标SL4,一切都正常了。在尝试运行应用程序时,您应该会在.cs文件中看到一个错误。
这个.cs文件对应的.xaml文件具有给定的行号和列,它就是正确的文件。检查您得到的ResourceDictionary引用-问题通常是其中一个错误需要修复 如果你的异常是来自应用程序的原因,那么它可能是你的一个合并目录,否则就是有问题的控件 还要检查您是否缺少样式的资源目录用法(如果您使用了ReSharper,则会有所帮助,因为您将在XAML设计时收到警告)
InnerException
和LineNumber
属性)是的,我同意。如果您能看到导致问题的关键是什么,那就太好了。我感谢你的帮助,但这并没有给我带来任何有用的东西:(你有这个库的源代码吗?如果你有正确的文件,第1739行位置:47将让你找到导致问题的资源。实际上是ComponentOne Silverlight SpellChecker组件。我刚刚将我的应用程序砍成碎片-删除app.xaml文件中的所有资源,但仍然失败。不过,我有一个来自ComponentOne工作正常。非常奇怪。但是,我会继续黑客攻击直到找到它!是的,这是一大浪费时间!谢谢你的建议。