locked
COMException thrown when there is no startup page in main assembly of Windows Store project RRS feed

  • Question

  • G'day,

    I have a bit of an issue with separating my views into an external project.

    I have 2 Projects.

    The first project is the main Windows Store application project.  The second is a class library.

    I have moved all the pages in my windows store project into the class library.  In the App.xaml.cs I am navigating to the startup page in the ClassLibrary using the following code

            protected override void OnLaunched(LaunchActivatedEventArgs args)
            {
    		base.OnLaunched(args);
    
    		var shell = new MyUserControl1();
    
    		Window.Current.Content = shell;
    
    		shell.NavigationFrame.Navigate(typeof(BlankPage1));
    			
    		Window.Current.Activate();
    	}


    the code in MyUserControl is:

    MyUserControl.xaml

    <UserControl
        x:Class="ClassLibrary1.NewFolder1.MyUserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:ClassLibrary1.NewFolder1"
        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 >
    
    		<Frame x:Name="RootFrame" />
    		
        </Grid>
    </UserControl>


    MyUserControl.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
    
    namespace ClassLibrary1.NewFolder1
    {
    	public sealed partial class MyUserControl1 : UserControl
    	{
    
    		public Frame NavigationFrame { get { return RootFrame; } }
    
    		public MyUserControl1()
    		{
    			this.InitializeComponent();
    		}
    	}
    }

    The exception I am getting is:

    Windows.UI.Xaml.Markup.XamlParseException: XAML parsing failed.
       at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
       at ClassLibrary1.NewFolder1.MyUserControl1.InitializeComponent() in c:\Users\andrew.smith\Documents\Visual Studio 2012\Projects\App2\ClassLibrary1\obj\Debug\NewFolder1\MyUserControl1.g.i.cs:line 30
       at ClassLibrary1.NewFolder1.MyUserControl1..ctor() in c:\Users\andrew.smith\Documents\Visual Studio 2

    The interesting thing is if I add a blank page in the Windows Store project, this works with no troubles without that blank page being referenced anywhere in the AppManifest, App.xaml.  What is happening in the application startup that would change the behaviour? 

    Here is a link to an example project:

    https://skydrive.live.com/redir?resid=250792A76A8E236E!147

    To test this, simply exclude and include the DummyPage.xaml and observe the differences.

    I know I'm missing something, but I can determine what that is.

    Cheers,

    Andrew


    Thursday, October 24, 2013 8:55 PM

Answers

  • This sounds vaguely familiar.  I believe that the this has something to do with the XAML parser not being initialized because the app has no XAML to parse (so you do need a dummy page).

    I will see if my teammates have more info.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, October 25, 2013 1:42 PM
    Moderator
  • Hi Jeff,

    Thanks for the information.

    I have come across a "fix" of sorts.  If you reference a UserControl as a resource within in the App.xaml ResourceDictionary.  It causes the XAMLParser to be initialized, removing the need for a dummy or default page in the Main assembly.

    For instance, I register a debugging UserControl as a resource which is defined in the second assembly (visible only when in debug mode, or initialized through an easter egg) in the App.xaml.  

    Makes for an elegant solution when I require some extra debugging help after I've deployed an application.

    I'm happy with this for now.

    Thanks very much for your help Jeff.  It's greatly appreciated.

    Andrew.

    Tuesday, November 5, 2013 7:40 PM

All replies

  • This sounds vaguely familiar.  I believe that the this has something to do with the XAML parser not being initialized because the app has no XAML to parse (so you do need a dummy page).

    I will see if my teammates have more info.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, October 25, 2013 1:42 PM
    Moderator
  • Hi Jeff,

    Thanks for your reply.

    Do you know of another way of initializing the XAML parser? I'm OK with having a root XAML page in the main assembly, but as a learning and understanding I'd like to be able to explain I need a XAML page in the main assembly.

    If you have extra information, I'd love some pointers.

    Cheers,

    Andrew


    Monday, November 4, 2013 1:54 PM
  • Hi Andrew,

    Honestly your scenario is such an edge case I have not really drilled into it much further.  One of my teammates remembers this scenario too when we were in preview support.  If I have time I will dig into this but honestly I have a lot of other things that take priority.  Bug me in a couple of weeks if you don't hear back from me to ping my brain back into looking at this.

    Jeff


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, November 4, 2013 2:05 PM
    Moderator
  • Hi Jeff,

    Thanks for the information.

    I have come across a "fix" of sorts.  If you reference a UserControl as a resource within in the App.xaml ResourceDictionary.  It causes the XAMLParser to be initialized, removing the need for a dummy or default page in the Main assembly.

    For instance, I register a debugging UserControl as a resource which is defined in the second assembly (visible only when in debug mode, or initialized through an easter egg) in the App.xaml.  

    Makes for an elegant solution when I require some extra debugging help after I've deployed an application.

    I'm happy with this for now.

    Thanks very much for your help Jeff.  It's greatly appreciated.

    Andrew.

    Tuesday, November 5, 2013 7:40 PM
  • Nice solution Andrew!  Thanks for sharing with the community!

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Tuesday, November 5, 2013 8:55 PM
    Moderator