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

Maybe resolved itself, after resetting emulator and couple vs.net restarts - will let you know
@MillerMark A few weeks ago you tweeted that something huge/incredible was coming....what is/was it? (I am hoping s… twitter.com/i/web/status/9…
Oddly, it won't hit breakpoints in XF .net standard 2 project now either
@JamesMontemagno Updated to 15.7 preview 2 Visual Studio - now having lots of odd thread issues when starting debug… twitter.com/i/web/status/9…