×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    System.Windows.Markup.XamlParseException when using NuGet packages

    I'm having this strange error in this project and I've never had it before.
    Basically this happens everytime I navigate through my pages and it's starting to get a little bit frustrating as I really can't find where the problem is.
    This project is basically a rewriting of an old one which has not this kind of problem.

    Once I get the exception, I expand my page var, its base type (PhoneApplicationType) and its base type again (System.Windows.Controls.Page).
    This one has a State property which reports this exception

    - State '((Microsoft.Phone.Controls.PhoneApplicationPage)(this)).State' ha generato un'eccezione di tipo 'System.InvalidOperationException' System.Collections.Generic.IDictionary<string,object> {System.InvalidOperationException}
    + base {System.InvalidOperationException: You can only use State between OnNavigatedTo and OnNavigatedFrom
    at Microsoft.Phone.Controls.PhoneApplicationPage.get_State()} System.SystemException {System.InvalidOperationException}
    Now, this is clearly messed up as I'm NOT using any kind of state here (I've got the exception also in another page where I'm using the state but I'm using it in the OnNavigatedTo method so the exception is nonsense even there).

    Here's my navigation code:
    Code:
    private void Button_Click(object sender, RoutedEventArgs e)
            {
                NavigationService.Navigate(new Uri("/MyComponent;component/Page.xaml", UriKind.RelativeOrAbsolute));
            }
    and here's the page XAML (no c# code as I've not changed anything from the auto-generated one):

    Code:
    <phone:PhoneApplicationPage
        x:Class="MyControl.MyPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MyControl"
        xmlns:bar="clr-namespace:AppBarUtils;assembly=AppBarUtils"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:lsp="clr-namespace:LSPlugins.plugins.widgets.PRIVATE"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d"
        shell:SystemTray.IsVisible="False">
    
        <UserControl.Resources>
            <local:MyModel x:Key="Model"/>              
        </UserControl.Resources>
    
        <Grid Grid.Row="1" x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="23*"/>            
            </Grid.RowDefinitions>  
            <Grid x:Name="ContentRoot" Grid.RowSpan="3">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="23*"/>                
                </Grid.RowDefinitions>
                <ContentPresenter Grid.RowSpan="3" x:Name="Background" Content="{Binding Path=Background, Source={StaticResource Model}}"/>
                <ContentPresenter Canvas.ZIndex="1" Grid.Row="1" x:Name="Content" Content="{Binding Path=Content, Source={StaticResource Model}}"/>
            </Grid>        
            <Image Grid.Row="0" x:Name="StatusBarImage" VerticalAlignment="Stretch" Source="/Assets/StatusBar.png"/>
        </Grid>
    
        <phone:PhoneApplicationPage.ApplicationBar>
            <shell:ApplicationBar x:Name="AppBar" IsVisible="True" IsMenuEnabled="True" Mode="Default">
                <shell:ApplicationBar.MenuItems>
                    <shell:ApplicationBarMenuItem Text="Save"/>
                    <shell:ApplicationBarMenuItem Text="Tutorial"/>                
                    <shell:ApplicationBarMenuItem Text="About"/>
                </shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarIconButton x:Name="add" IconUri="/Assets/AppBar/add.png" Text="Add"/>
                <shell:ApplicationBarIconButton x:Name="add2" IconUri="/Assets/AppBar/feature.camera.png" Text="Add2"/>
                <shell:ApplicationBarIconButton x:Name="apply" IconUri="/Assets/AppBar/check.png" Text="Apply"/>
                <shell:ApplicationBarIconButton x:Name="export" IconUri="/Assets/AppBar/save.png" Text="Export"/>
            </shell:ApplicationBar>
        </phone:PhoneApplicationPage.ApplicationBar>
    
        <i:Interaction.Behaviors>
            <bar:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
        </i:Interaction.Behaviors>
    
    </phone:PhoneApplicationPage>
    Now, the funny thins is that everything works if I remove the
    Code:
    <bar:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
    line.

    In another page I'm using Coding4Fun Toolkit and I've got the same problem: when I remove their ColorPicker, the page loads. With the ColorPcker, the same exception is thrown.

    This thin is driving me mad because I don't understand what the hell is wrong with my app!

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    I do not really understand the logic, but based on some samples online, and bundled with AppBarUtils itself, Id may refer to Text. And if it happens to be case sensitive, there is a mismatch, which may or may not have something to do with the problem.
    Your code:
    <shell:ApplicationBarIconButton x:Name="add" IconUri="/Assets/AppBar/add.png" Text="Add"/>
    ...
    <bar:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
    theirs:
    Quote Originally Posted by FixedAppBarPage.xaml
    <shell:ApplicationBarMenuItem Text="clear"/>
    <shell:ApplicationBarIconButton IconUri="/icons/appbar.add.rest.png" Text="add"/>
    ...
    <abu:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
    <abu:AppBarItemCommand Type="MenuItem" Id="clear" Command="{Binding ClearCommand}"/>

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    Quote Originally Posted by wizard_hu_ View Post
    I do not really understand the logic, but based on some samples online, and bundled with AppBarUtils itself, Id may refer to Text. And if it happens to be case sensitive, there is a mismatch, which may or may not have something to do with the problem.
    Your code:theirs:
    Thank you for your reply.

    Actually this was just a typo as I changed some code manually before posting it.

    I've got this problem with AppBarUtils, Coding4Fun ColorPicker and now even with Microsoft Toolkit ListPicker.
    When I've got some of this objects in my XAML, it throws the exception.

    As a side note, the page is perfectly fine in the designer, no wrong xaml code.

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    523

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    Perhaps there are some issues with the Coding4Fun Toolkit. My suggestion would be to copy your code into a new project and first only install the Microsoft Toolkit and get everything working that way. Later on you can add the other packages via Nuget to identify exactlly what goes wrong as it seems one of the NuGet packages is not exactlly compatible.

    Are you targting WP7 or WP8 only?

  5. #5
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    WP8 only.

    I can try removing the Coding4Fun Toolkit, but I'm quite sure that the problem will remain as I've got it even when there's no C4F XAML in my pages.

    If I don't use external libs, the page loads fine, but adding just one of them (no matter if it's the case of C4F or the MS Toolkit) causes the exception!

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    574

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    Just as an FYI, XAML parsing isn't very good is Visual Studio and you can't rely on Design Mode to pick up a lot of errors. In fact, Design Mode is quite limited in what it can execute and sometimes valid XAML won't "run" because it relies on a component that won't execute - yet it will compile and run okay.

    XAML is evaluated fully at run-time which means a) even the compiler doesn't help much b) you can only produce certain crashes when you run the app. It's annoying.

    The hope is that things will improve over time with future versions of Visual Studio (2013 and beyond) and improvements to the platform (WinRT).

    In regards to your specific problem, try and remove as much as possible from the XAML you're adding - only use what's absolutely necessary and see if that helps.

    Also, make sure the namespace imports at the top of the file are correct, they're a common cause of error.

  7. #7
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    I've tried now with this minimal page, still no success.

    Code:
    <phone:PhoneApplicationPage
        x:Class="MyNamespace.MyClas"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d"
        shell:SystemTray.IsVisible="True">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!--TitlePanel contiene il nome dell'applicazione e il titolo della pagina-->
            <StackPanel Grid.Row="0" Margin="12,17,0,5">
                <TextBlock Text="App" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock Name="PageTitle" Text="{Binding Path=Model.Name, StringFormat='{}{0} Settings'}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
            </StackPanel>
    
            <!--ContentPanel - inserire ulteriore contenuto qui-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <toolkit:ListPicker/>
            </Grid>
        </Grid>
    </phone:PhoneApplicationPage>
    (The XAML code has no errors, if you find one is because I deleted the page from Visual Studio and I quickly rewrote it here).

    Removing the ListPicker makes the page load successfully.
    Notice that I don't have Coding4Fun Toolkit in my namespace so this problem depends on something else
    Last edited by StepTNT; 2013-09-23 at 12:04.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    574

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    Is the ListPicker from the WP Toolkit?

  9. #9
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: System.Windows.Markup.XamlParseException when using NuGet packages

    It is, and I'm forced to write this useless stuff because it won't allow me to post a message that's shorter than 10 characters

Similar Threads

  1. "System.Windows.Data Error" with a custom ListBoxItemStyle why ?
    By TheTraPpeur in forum Windows Phone General
    Replies: 4
    Last Post: 2013-08-08, 20:44
  2. Replies: 5
    Last Post: 2008-09-23, 05:48
  3. Install Python 3.0a5 on Windows Vista System
    By Hugh Pittman in forum Symbian
    Replies: 5
    Last Post: 2008-06-09, 11:17
  4. inactivity timer, backlight, system dialogue windows.
    By davidmaxwaterman in forum Series 40 & S60 Platform Feedback Archive
    Replies: 0
    Last Post: 2007-05-24, 03:11
  5. Replies: 0
    Last Post: 2004-01-19, 22:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×