Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

silverlight - How do you debug a XamlParseException?

I'm trying to use a 3rd party component in my Silverlight application and when I try to create an instance of the control, I get a 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()}

How can I debug this? How do I know what file line 1739, Position 47 is in?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could be a bit of a bugger to find. Basically try to gather as many details as possible from the debugger.

  1. Set the debugger to break on XamlParseException.
  2. Have a look at the callstack. It could be possible that the offending control's constructor is on the callstack.
  3. When paused go to the Locals debug window to see if any parameters to the function reveal more about which component this is.
  4. If not double-click the next stack entry down and go to step 3.
  5. Repeat steps 3 and 4.

After I wrote this I realised that the control's constructor is indeed on the callstack and it is SpellCheckerSample. Very likely it is .XAML page for that control. If you can get access to the source, the file name is most likely something like SpellCheckerSample.xaml.

The error itself is pretty straight forward, looks like there multiple things defined with the same key in the same ResourceDictionary. The below code will cause this to happen:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...