views:

547

answers:

4

Hi

I'm getting a AG_E_UNKNOWN_ERROR when running my Silverlight project. The project is ported from WPF, and from what I can gather around the web, I'd assume it's related to something invalid in my XAML

EDIT C# Control sources can be found here: SilverlightCalendar/Controls

Here's Generic.xaml, the styles for my application.

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:SilverlightCalendar.Controls">

    <Style TargetType="{c:CalendarTimeslotItem}">
        <Setter Property="Content" Value="{Binding}" />
        <Setter Property="Background" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:CalendarTimeslotItem}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="#A5BFE1"
                            BorderThickness="0,0.5,0,0.5"
                            x:Name="bd"
                            Height="22">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{c:CalendarLedgerItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:CalendarLedgerItem}">
                    <Border Background="#E3EFFF"
                            BorderBrush="#6593CF"
                            BorderThickness="0,0,1,1"
                            Height="44" Width="50">
                        <StackPanel Orientation="Horizontal" 
                                    VerticalAlignment="Center" 
                                    HorizontalAlignment="Center">
                            <TextBlock Text="{TemplateBinding TimeslotA}" 
                                       Foreground="#9493CF" FontSize="16" Margin="0,3,0,0"/>
                            <TextBlock Text="{TemplateBinding TimeslotB}" 
                                       Foreground="#9493CF"  Margin="1.5,0,0,0"/>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{c:CalendarDay}">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <c:TimeslotPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:CalendarDay}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <StackPanel x:Name="PART_CalendarTimeslots" />
                            <ItemsPresenter />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{c:CalendarLedger}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:CalendarLedger}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <StackPanel x:Name="PART_CalendarLedgerItems" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{c:Calendar}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:Calendar}">
                    <Border Background="#E3EFFF"
                            BorderBrush="#6593CF"
                            BorderThickness="2,2,2,2">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border BorderBrush="#6593CF" BorderThickness="0,0,0,1" 
                                    Grid.Column="0" Grid.Row="1" />
                            <Border BorderBrush="#6593CF" BorderThickness="0,0,0,1" 
                                    Grid.Column="1" Grid.Row="1" />
                            <ScrollViewer Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="50" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <c:CalendarLedger Grid.Column="0" />
                                    <c:CalendarDay Grid.Column="1" x:Name="PART_CalendarDay" />
                                </Grid>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{c:CalendarAppointmentItem}">
        <Setter Property="StartTime" Value="{Binding StartTime}" />
        <Setter Property="EndTime" Value="{Binding EndTime}" />
        <Setter Property="Width" Value="{Binding ActualWidth, ElementName=CalendarTimeslots}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{c:CalendarAppointmentItem}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="300" />
                            <ColumnDefinition Width="300" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" 
                                Grid.Column="{Binding Column}" 
                                Grid.ColumnSpan="{Binding ColumnSpan}"
                                CornerRadius="4,4,4,4" 
                                BorderThickness="1,1,1,1" 
                                BorderBrush="#5D8CC9" 
                                Background="{Binding Background}"
                                Margin="1,1,5,1" 
                                Padding="5,5,5,5">
                            <Border.Effect>
                                <DropShadowEffect Opacity="0.5" />
                            </Border.Effect>
                            <TextBlock 
                                IsHitTestVisible="False"
                                Foreground="{Binding Foreground}"
                                VerticalAlignment="Top"
                                MaxHeight="20"
                                LineHeight="20"
                                FontFamily="Segoe UI" 
                                FontSize="12.75" 
                                FontWeight="DemiBold"
                                FontStretch="Medium"
                                TextWrapping="WrapWithOverflow"
                                Text="{Binding Subject}" />                            
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
A: 

If you look carefully that error usually has a line number which relates to the lines in the XAML.

AnthonyWJones
Yes, the entry point of the application! Which is useless information beyond that the styles are invalid.
Claus Jørgensen
+3  A: 

Recently debugged a bunch of these. When I can't see the problem I just comment big chunk of the XAML until I don't get the error and then uncomment parts until I can find a spot causing the exception.

EDIT: for starters get rid of curly brackets in TargetType="{c:CalendarTimeslotItem}". Just tried and I get the exception this way. Just use TargetType="c:CalendarTimeslotItem"

Alan Mendelevich
Very good debugging hint, Alan. You can even apply binary search here :).
Anvaka
hmm, tried that, and it had no effect. I guess the C# that generates the classes isn't compatible (even it compiles). Any ideas for debugging this futher?
Claus Jørgensen
You can easily determine if the problem is in XAML (my guess it is): just comment everything in your xaml and see if you get some "normal" exception instead of that AG_E_UNKNOWN_ERROR stuff.
Alan Mendelevich
I removed the curly brackets, and the exception remains the same.
Claus Jørgensen
+1  A: 

Configure your system to break when exceptions are thrown.

  1. In Visual Studio select the Debug menu, then Exceptions....

  2. In the Exceptions dialog box mark the Thrown check box next to Common Language Runtime Exceptions.

  3. Start you project in the debugger (make sure that Silverlight debugging is enabled).

You will most likely see some irrelevant exceptions being thrown (just continue debugging) but at one point you should see the offending XAML exception. Inspect the exception to see if you can figure out the line number. If the exception is being thrown in a code-behind file you can infer the XAML file from the code-behind file.

Martin Liversage
The XamlException is still AG_E_UNKNOWN_ERROR.
Claus Jørgensen
To be precise:XamlParseException: AG_E_UNKNOWN_ERROR [Line: 12 Position: 53]The line number is the entry point of my user control, and the user control is written in C# and styled with XAML. Which alas, is as stated already, completely useless information -.-
Claus Jørgensen
You have to look at line 12 position 53 in the corresponding XAML file to see what is causing the problem. I don't see how this is useless information?
Martin Liversage
Because that code is <control:Calendar /> , which is a ENTRY POINT. Every possible piece of code that's used to create the subcontrol, ie. about 1000 lines of code, could cause this. It's basically equal to a debugger saying your code error is in Main(). Happy guessing ;-)
Claus Jørgensen
That is the exact problem my answer tries to solve. My instructions is an attempt to catch the exception caught in the first place when some deeply nested XAML is read and not at a higher level when you top-level window fails at loading. At least that is my strategy for solving XAML problems like that.
Martin Liversage
It is however, not working on this infamous generic error message :(
Claus Jørgensen
OK, if there is no "inner" exception from loading "nested" XAML you probably have to do as Alan Mendelevich suggested.
Martin Liversage
A: 

Problem solved (And other arise, but that's for another day)

In my case the use of other bounded properties in the template were causing the issue.

    <Style TargetType="c:CalendarTimeslotItem">
    <!--<Setter Property="Content" Value="{Binding}" />-->
    <Setter Property="Template">

And

    <Style TargetType="c:CalendarAppointmentItem">
    <!--<Setter Property="StartTime" Value="{Binding StartTime}" />-->
    <!--<Setter Property="EndTime" Value="{Binding EndTime}" />-->
    <Setter Property="Template">
Claus Jørgensen