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.

 

System.Windows.Controls.Layout.Toolkit.dll
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll

 

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.

 

Author

David

comments powered by Disqus

Categories

Recent Tweets

Retweeted by @dyardy Hey C# peeps, we’re trying C# in browser with reference content. Try it here: docs.microsoft.com/dotnet/csharp/… reply with feedback /cc @LadyNaggaga
23 Amazing Vintage Photographs Taken Inside WWII Tank Factories ~ vintage everyday vintag.es/2017/10/23-ama…
When is AI NOT Search? Artificiality intelligence==Search Engine (there cases when this is not true)
@projectedxyz Large data vs big data? Industry has so misused buzz words to sell products, and so you end up nothi… twitter.com/i/web/status/9…