Xaml Parse Exception
I have been playing around with some great tutorials on Silverlight/WPF and calling external API’s for a little CRM project I am working on. Today I came across a weird error and thought I would document it here so next time it happens – I'll know how to fix it!
So Visual Studio 2008 gives a nice split view so you can see the Xaml you’re working on & a preview of the results. I was adding Style elements to my App.xaml page – and suddenly the preview stopped displaying. I tried to compile & run the app. It compiled fine, but got to the InitialiseComponent step, and threw a very nondescript error: AG_E_Unknown_Error […]
Looking at my Page.xaml I also noticed that the style element I had just created & linked to was underlined in blue squiggles:
Turns out it was just because of an error in the style definition in the App.xaml page. Even with the intellisense prompts, I had still managed to miss something! I had forgotten to put the # in the beginning of the Foreground property colour definition. As soon as I added that & saved – all was once again happy! :)
Comments
Anonymous
November 30, 2008
Did you try with ExpressionBlend? I haven't tried for this error, but in many other cases, I have seen blend giving more detailed error information right in designer. This may be since the VS support for SL designer is still not completeAnonymous
November 30, 2008
Thanks for that suggestion Atul! I haven't got Expression Blend on this laptop but will try it when I get a chance and see if it does give a more detailed suggestion as to whats missing?Anonymous
March 16, 2009
Haha i just ran into something similar. In my case I had # in there correctly but instead of #12345678 i had #1234567Anonymous
October 08, 2010
THERE IS A SOLUTION FOR THIS :-) THIS REASON FOR THIS EXCEPTION DUE TO COMMON OVERLOOK MANY OF OUR DEVELOPERS DO. If there is no matching delegated method for the method name bound to your event in your XAML, you would get this exception. i.e., Check the signature (arguments/parameters) of your method in your CODE BEHIND FILE which was bound to your event in your XAML FILE. This generally happens while there is a rework or correction being in a project where the developers change the SIGNATURE of the delegate to that event handler and forget to update the arguments in the delegated methods in their CODE BEHIND FILE in client application whose names were bound to respective events in corresponding XAML file. EXAMPLE: SUPPOSE YOU HAVE AN EVENT LIKE THIS IN YOUR CUSTOM CLASS.... public event EventHandler<System.Windows.Controls.SelectionChangeEventArgs> SelectionChanged; OR AN EVENTHANDLER (DELEGATE) AND CORRESPONDING AN EVENT LIKE THIS..... public delegate void SelectionChangeEventHandler(object sender, System.Windows.Controls.SelectionChangeEventArgs e); public event SelectionChangeEventHandler SelectionChanged; AND A DELEGATED METHOD WHICH IS CALLED FOR THIS EVENT LIKE THIS..... void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangeEventArgs e) { ...some code.... } AND IN XAML YOU HAVE BOUND THE EVENT LIKE THIS IN YOUR CLIENT APPLICATION..... <local:ComboBox Name="tngCmb" SelectionChanged="tngCmb_SelectionChanged" /> AND CORRESPONDING CODE BEHIND IS LIKE THIS IN YOUR CLIENT APPLICATION..... void tngCmb_SelectionChanged(object sender, System.Windows.Controls.SelectionChangeEventArgs e) { ...some code... } [[[[[[[[[[[[[[[[NOW WATCH CAREFULLY]]]]]]]]]]]]]] IF YOU HAVE CHANGED YOUR EVENT IN YOUR CUSTOM CLASS TO SOMETHING LIKE THIS... public event EventHandler<MyNameSpace.MySelectionChangeEventArgs> SelectionChanged; OR YOUR EVENTHANDLER (DELEGATE) AND TIS CORRESPONDING EVENT LIKE THIS..... public delegate void SelectionChangeEventHandler(object sender, MyNameSpace.MySelectionChangeEventArgs e); public event SelectionChangeEventHandler SelectionChanged; AND YOUR DELEGATED METHOD WHICH IS CALLED FOR THIS EVENT LIKE THIS..... void ComboBox_SelectionChanged(object sender, MyNameSpace.MySelectionChangeEventArgs e) { ...some code.... } [[[[[[[[[THEN IMMEDIATELY YOU HAVE TO]]]]]]]]]] CHANGE YOUR CODE BEHIND IN YOUR CLIENT APPLICATION TO..... void tngCmb_SelectionChanged(object sender, MyNameSpace.MySelectionChangeEventArgs e) { ...some code... } [[[[[[[[[[[[DONT FORGET]]]]]]]] IF YOU FORGET OR OVERLOOK THIS, THE VISULA STUDIO COMPILER WILL NEVER WARN YOU BUT YOU WOULD BE GETTING THIS EXECPTION "XamlParseException" exception showing something like "Failed to assign to property". [[[[[AND YOU WOULD PANIC]]]]]]]] AS YOU WOULD BE NOT ABLE TO STOP AT YOUR BREAPOINT AT/IN InitializeComponent() METHOD OF YOUR CLIENT APPLICATION. [[[[[[[[[SO BE CAREFUL WHILE CODING :-) ]]]]]]]]]]]] Your Well Wisher** Sriram Naresh Akula (Project Lead) MOBILE: +91-9989697948 BLOG: cybernaresh.spaces.live.com DON'T HESITATE TO CALL ME ON MY MOBILE FOR ANY HELP ANYTIME 24/7 :-)