Error Element is already the child of another element. [Line: 0 Position: 0]
-
Wednesday, April 13, 2011 2:19 AM
Hi gang,
Seems to be a small issue with the VB LightSwitch VS templates. Using the VB project template, when I run through the scenario outlined here: http://blogs.telerik.com/blogs/posts/11-04-12/how_to_telerik_reporting_in_microsoft_lightswitch_beta_2.aspx , I receive an Element is already the child of another element. [Line: 0 Position: 0] error. The C# template is fine.
Let me know if you need any other information from me, or if there is a workaround so that I can get this scenario to work using the VB templates.
Cheers,
Paul
PP
All Replies
-
Wednesday, April 13, 2011 5:32 AMModerator
Hi Paul,
At what point in the walkthrough is this error occurring? If you create a different project using the VB template are you also seeing this error?
Regards,
Steve Hoag Microsoft aka the V-Bee -
Wednesday, April 13, 2011 3:53 PM
Hi Steve,
The error occurs when running (in debug) the solution; when I open the screen.
I believe this may be an issue with the creation of the xaml control. When adding the control, the xaml does not include a valid Namespace.
For example (the for assemblies in the article are already added as a reference):
- In the File View of the solution, I right-click to add a New Item and then selected to add new Silverlight User Control.
- The following is an example of the xaml that results (note the "x:Class=".MySilverlightControl".
<UserControl x:Class=".MySilverlightControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> </Grid> </UserControl>
- The class file that results (MySilverlightControl.vb) also does not contain a Namespace. E.g.
Partial Public Class MySilverlightControl Inherits UserControl Public Sub New InitializeComponent() End Sub End Class
- I attempted to add the Telerik control when I tried to build the client, errors were thrown. I then made updates to include a namespace and such, but I would always end up with the error when running the application.
Interesting was that, even when updated the xaml and class with a namespace, when selecting the Telerik.ReportViewer.Silverlight reference, VS would crash and restart. I could add the other Telerik references, just not that one.
What I did to get thins to work is...
- In the File View of the solution, I right-click to add a New Item and then selected to add new Silverlight User Control.
- I updated resulting class file with a namespace and import...
Imports System.Windows.Controls Namespace MyNamespace Partial Public Class MySilverlightControl Inherits UserControl Public Sub New() InitializeComponent() End Sub End Class End Namespace
- I then updated the xaml with the appropriate namespace information.
<UserControl x:Class="MyNamespace.MySilverlightControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> </Grid> </UserControl>
- I Rebuilt the Client
- I went back in and updated the xaml for the User Control to include the control.
<UserControl x:Class="MyNamespace.MySilverlightControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:telerikReporting="clr-namespace:Telerik.ReportViewer.Silverlight;assembly=Telerik.ReportViewer.Silverlight" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <telerikReporting:ReportViewer telerik:StyleManager.Theme="Office_Blue" /> </Grid> </UserControl>
- I Rebuilt the Client
- Back in the logical view, I created a new Editable Grid Screen where I then selected to add a custom control to the screen.
- I first used the Add Reference.., to add references to each of the Telerik assemblies, and then added a reference to the MyApplication.Client project. I then added the MySilverlightControl.
- Ran the project and all is good.
I hope this information helps. If you need any more details, let me know.
Thanks again Steve,
Paul
PP
- Proposed As Answer by Yann Duran Thursday, May 12, 2011 9:42 AM
-
Wednesday, May 11, 2011 1:40 PM
Paul, as usual you are a genius :)
This is a REALLY ugly error message that does not really tell you what the problem is. Your post is the ONLY clue I was able to find. Let me explain my situation in hope that it helps others.
1) I want to display images in a wrap panel. If I use a wrap panel on my Silverlight custom control I get the error "Error Element is already the child of another element. [Line: 0 Position: 0]". That it. No help of fixing this, go home, thanks for playing :)
2) I read Paul's, description and the issue is basically:
A) The Wrap Panel is part of "System.Windows.Controls.Toolkit", and in my Silverlight custom control project I do have a reference to theis assembly, but that is not enough.
B) When I put that Silverlight custom control in LightSwitch, that reference is NOT in the LightSwitch project and the error will be thrown
C) To solve the problem, add the references needed for your Silverlight custom control to the LightSwitch project (please understand that this is a huge unconnected leap of logic that is only possible if you have read Paul's detailed post).
1) On the LightSwitch Screen designer, select Add Custom Control.
2) When the box comes up, click Add Reference and add any references you need (in my case i needed "System.Windows.Controls.Toolkit")
3) Click Cancel
4) Enjoy! :)
- Proposed As Answer by i am rommel Saturday, May 28, 2011 11:48 AM

