3

I get the following error when I show this window from another window in my application:

XamlParseException occurred 'Set connectionId threw an exception.' Line number '4' and line position '25'.

With an inner exception of:

{"Unable to cast object of type 'System.Windows.Controls.TabControl' to type 'WpfApplication1.Window1'."}

My xaml code is as follows:

 <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="482" Width="603" Loaded="Window_Loaded">
<Grid>
    <TabControl Height="402" HorizontalAlignment="Right" Margin="0,0,12,0" Name="tabControl1" VerticalAlignment="Top" Width="569" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
        <TabItem Header="tabItem1" Name="tabItem1">
            <Grid></Grid>
        </TabItem>
        <TabItem Header="tabItem2" Name="tabItem2">
            <Grid Height="374" Width="563">
                <ListView Height="317" HorizontalAlignment="Left" Margin="6,10,0,0" Name="listView1" VerticalAlignment="Top" Width="550">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="IP" DisplayMemberBinding="{Binding CustomerIP}"/>
                            <GridViewColumn Header="Host Name" DisplayMemberBinding="{Binding HostName}"/>
                            <GridViewColumn Header="MAC" DisplayMemberBinding="{Binding MAC}"/>
                            <GridViewColumn Header="Avg. Ping Time" DisplayMemberBinding="{Binding time}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </TabItem>
        <TabItem Header="tabItem3" Name="tabItem3">
            <Grid Height="307" />
        </TabItem>
    </TabControl>
    <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="330,408,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    <Button Content="Next" Height="23" HorizontalAlignment="Right" Margin="0,408,12,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    <Button Content="Back" Height="23" HorizontalAlignment="Left" Margin="411,408,0,0" Name="button3" VerticalAlignment="Top" Width="75" IsEnabled="False" />
    <Rectangle Height="0" HorizontalAlignment="Left" Margin="13,40,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="453" />
    <ProgressBar Height="23" HorizontalAlignment="Left" Margin="5,408,0,0" Name="progressBar1" VerticalAlignment="Top" Width="319" Visibility="Hidden" />
    <Button Content="Remove" Height="23" HorizontalAlignment="Left" Margin="486,363,0,0" Name="button4" VerticalAlignment="Top" Width="75" IsEnabled="False" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="15,363,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
    <TextBox Height="23" HorizontalAlignment="Left" Margin="162,363,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
    <Label Content="To" Height="28" HorizontalAlignment="Right" Margin="0,360,421,0" Name="label1" VerticalAlignment="Top" />
    <Button Content="Search" Height="23" HorizontalAlignment="Left" Margin="288,363,0,0" Name="button5" VerticalAlignment="Top" Width="75" Click="button5_Click" />
</Grid>

If you need my C# code to figure out this problem I can Email it to you, but it is against company policy to put that code on the web (and I enjoy my job... I dont want to get fired)

Please keep in mind that I normaly develop in VB.net, and C#.net is very new to me, so if you could please detail your explanations for a beginner that would be appreciated.


c#.net vs2010 Windows Vista x64 Intel Core 2 Quad

Pero P.
  • 25,813
  • 9
  • 61
  • 85
Reid Kersey
  • 31
  • 1
  • 2
  • The ugliness of that code points towards the use of a GUI-designer, using a `Grid` without creating rows and columns is quite pointless... – H.B. Aug 07 '11 at 04:48
  • In VB you never have to write this kind of code, so please excuse the ugglieness... This is a mish-mash of blogCode vs2010 autogen code. – Reid Kersey Aug 07 '11 at 04:56
  • I'd recommend hand-coding, otherwise you'll probably end up with something unreadable and unmaintainable sooner or later. – H.B. Aug 07 '11 at 05:04
  • 1
    What happens if you remove `Loaded="Window_Loaded"`? – H.B. Aug 07 '11 at 05:50
  • Luks to me like a code behind error than XAML parser error. Window_Loaded looks like the culprit to me. – WPF-it Aug 07 '11 at 07:04
  • @Reid, you have to write this kind of code in VB too, if you use WPF. – svick Aug 07 '11 at 10:39

4 Answers4

10

Try Rebuilding the complete solution from Solution Explorer.

Samarth Agarwal
  • 2,044
  • 8
  • 39
  • 79
4

Since the outer exception mentions the connectionid the invalid cast has to be done in a automatically generated code file that accompanies the window and is found in the obj folder of the project. It should be called Window1.g.cs.

Look at the Connect method, there should be a case with #line 4 ... where it tries to attach the Window.Loaded event, maybe you can see why it tries to cast the way it does.

H.B.
  • 166,899
  • 29
  • 327
  • 400
2

I received a similarly titled error and it was because the project was configured to build in AnyCPU, but a dependent assembly was set as x86. Changing the project to x86 resolved this issue.

StingyJack
  • 19,041
  • 10
  • 63
  • 122
  • Just found http://stackoverflow.com/questions/4615597/xamlparseexception-after-deploying-wpf-project as well. – StingyJack Aug 13 '13 at 14:05
0

It is likly due to some missing ddl. check the inner exception and you will have a clue about the missing dll.

Zubaer Naseem
  • 454
  • 7
  • 14