gpt4 book ai didi

silverlight - 如何调试 XamlParseException?

转载 作者:行者123 更新时间:2023-12-03 22:36:22 25 4
gpt4 key购买 nike

我正在尝试在我的 Silverlight 应用程序中使用第 3 方组件,当我尝试创建控件的实例时,我收到 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 位在哪个文件中?

最佳答案

可能有点难找。基本上尝试从调试器收集尽可能多的详细信息。

  • 将调试器设置为在 XamlParseException 上中断.
  • 看看调用堆栈。违规控件的构造函数可能在调用堆栈上。
  • 暂停时,转到 Locals 调试窗口以查看该函数的任何参数是否显示了有关这是哪个组件的更多信息。
  • 如果不是,请向下双击下一个堆栈条目并转到第 3 步。
  • 重复步骤 3 和 4。

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

    错误本身非常简单,看起来在同一个 ResourceDictionary 中使用相同的键定义了多个事物。下面的代码将导致这种情况发生:
    <Window.Resources>
    <myConverters:BananaToCarrotConverter x:Key="StupidestConverterEver" />
    <myConverters:BananaToAppleConverter x:Key="StupidestConverterEver" />
    <Window.Resources>

    关于silverlight - 如何调试 XamlParseException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2879312/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com