Element is already the child / System.Windows.Markup.XamlParseException --> PivotControl Error

I have been working with Silverlight PivotViewer control and recently came across problem with the display of the control.  I have a solution with multiple projects one of which is a Silverlight application.  Everything would compile without any error.  When browsing to the form/page with the control I would immediately get an exception on the InitializeComponent(); method within the Silverlight UserControl.  This method is called before loading any pivot cxml data.


I have seen this component through odd errors or fail to load when there is javascript errors on the page or a failure of any ajax method.  The error that is thrown is as follows…


{System.Windows.Markup.XamlParseException: Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 15 Position: 43] ---> System.Windows.Markup.XamlParseException: Element is already the child of another element. [Line: 0 Position: 0]

   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 PivotView.Viewer.InitializeComponent()

   at PivotView.Viewer..ctor()}



If searching Google you will see a number of posts on errors surrounding ‘XamlParseException’, ‘Styles’, ‘Element is already the child’ etc.  Without help from these posts, I finally came across the solution.  I found the error was the result of some missing references in the Silverlight project.  The components missing can be found in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin (which is installed as part of the most recent Silverlight Toolkit).  References to the following components was necessary.




If you having issues, rename the xap file (adding .zip) and take a look to ensure those dlls are included.


I thought I would post this information for others as well as a reminder to myself.  If you have any questions, let me know.




comments powered by Disqus


Recent Tweets

@jeffrey_doucet @Brian_Bancroft Canadians, self define themselves as NOT American, rather than being Proud Canadians
Retweeted by @dyardy Why do so many Canadians obsess over American policy that won’t impact us while being fairly ambivalent to day-to-d… twitter.com/i/web/status/9…
@melrobbins I was looking for 50$ earlier today, and still can't find it...ideas :)
Trump Watches Up To 8 Hours Of TV Per Day | HuffPost #SmartNews ===that explains everything huffingtonpost.com/entry/trump-te…
Retweeted by @dyardy Boston https://t.co/QmtMIF8P0F