XamlParseException - Trying to do Caliburn.Micro Tutorial

Topics: Bugs
Jul 20, 2011 at 3:31 PM

Hello.  I'm trying to do a Caliburn.Micro tutorial (http://deanvmc.me/blog/index.php/2011/06/23/caliburn-micro-for-the-rest-of-us-part-0/) (http://deanvmc.me/blog/index.php/2011/06/24/caliburn-micro-for-the-rest-of-us-part-1/).  I'm fairly new to C#, never worked in a dev shop, and all the projects I've done have been on my own (so I may not know all the right terminology).  This is my first try at MVVM.  I started off not being able to get part 0 to work.  Apparently, selecting a WP 7.1 type project causes Caliburn.Micro to no longer work.  It put files in the directory that weren't part of the tutorial, and I couldn't ever get it to build.  After a few tries, deleting teh project and starting over, I tried a 7.0 project, and was able to get Part 0 of the tutorial to build.  Success!  (In part 0 there is no UI, so nothing to run, but it builds).

Then I tried Part 1 (the second link).  I entered the project just as directed.  When I got done, it built.  Then when I try to run it, no good.  I get a XamlParseException in the InitializeComponent method.  The stack trace follows:

System.Windows.Markup.XamlParseException occurred
  Message=System.InvalidOperationException: Creating multiple instances of PhoneApplicationService is not supported.
   at Microsoft.Phone.Shell.PhoneApplicationService..ctor()
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
   at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
   at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
   at MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte* pXamlStr, UInt32 cAssemblyStrLength, String assemblyStr)
   at MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at CaliburnSample.App.InitializeComponent()
   at CaliburnSample.App..ctor()
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
   at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
   at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
   at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer)
 [Line: 0 Position: 0]
  LineNumber=0
  LinePosition=0
  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at CaliburnSample.App.InitializeComponent()
       at CaliburnSample.App..ctor()
       at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
       at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
       at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
       at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
       at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
       at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
       at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer)
  InnerException: System.InvalidOperationException
       Message=Creating multiple instances of PhoneApplicationService is not supported.
       StackTrace:
            at Microsoft.Phone.Shell.PhoneApplicationService..ctor()
            at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
            at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
            at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
            at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
            at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
            at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
            at MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte* pXamlStr, UInt32 cAssemblyStrLength, String assemblyStr)
            at MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString)
            at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
            at CaliburnSample.App.InitializeComponent()
            at CaliburnSample.App..ctor()
            at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
            at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
            at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
            at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
            at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
            at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
            at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer)

Here's the Xaml:

<phone:PhoneApplicationPage 
    x:Class="CaliburnSample.Views.AlbumSummaryView"
    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"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True">

	<StackPanel>
		<TextBlock
			x:Name="Album_Title" />
		  
	</StackPanel>

</phone:PhoneApplicationPage>

 

Even after deleting the entire project, and starting over, three times, I get the same error.

I'm wondering if there is either something wrong with VS, or the WP Tools, or even just my installation of these.  I have had to deal with this same error on two other apps that I've built.  In the first one, I had a pivot page with several textboxes.  I discovered that if I deleted all but one of the textboxes from the markup, it would work.  As soon as I added another textbox, the app broke.  I reentered the markup on a new page, and replaced the old page, and was able to get it working that way, copy/pasting the codebehind into the new page, but manually entering the markup, as copy/pasting the markup gave me the same error.

In the second app, again, a pivot page with many textboxes, I got the same error again.  This time I discovered something that may have been the problem in the first app, but I didn't get this detailed with it (I don't remember if I treid adding a new textbox without a style in the original project).  I learned that the style I was applying to textboxes was the problem.  I used the same style from the first app, and learned that if I applied it to one textbox, the app worked.  If I applied it to more than one, the app broke.  Reentering the markup into a new page did NOT solve the problem this time, so I had to resort to manually setting the properties on every textbox. 

Basically, I'm wondering if anyone could take my project - based on the tutorial linked above - and try it on your computer to see if it will run.  If so, then the problem must be in my installation, and I'll try reinstalling everything.  I'm not sure if it is a problem with the Mango Beta 2 tools, or VS, or what.  My setup is as follows:

  • i7 processor
  • 8GB Ram
  • VS 2010 Ultimate
  • WP Mango Beta 2 SDK
  • Silverlight Phone tools

Thanks.

Rich

 

Jul 20, 2011 at 5:08 PM

I downloaded the Part 1 of the tutorial, and it works as expected. 
You should install "Windows Phone Developer Tools 7.0" (the last official version before Mango Beta) since CM is only maintained against v7.0 (you can find it here: http://create.msdn.com/en-us/resources/downloads).

Hope it helps.

Jul 20, 2011 at 6:33 PM

Hi,

 

I am the author of the blog, I have been doing some testing and it seems to be that Nuget defaults a 'Silverlight' installation when you use it on a newly created project. You have two options at the moment if you want to use Caliburn.Micro with Windows Phone 7.1 (Beta). Option 1 is to create a new Windows Phone 7.0 project, install from Nuget and then perform an upgrade to 7.1 by right clicking the project in the solution explorer. The second option is to reference the DLL's manually and add in a boothstrapper. Once you have done either of these Caliburn.Micro will work fine with 7.1. I have done extensive testing with my own 7.1 app and so far there has been no issue.

 

I will be updating the blog this evening to reflect this new information.

Jul 20, 2011 at 8:07 PM

Contacted to OP for a sample, the problem stemmed from not clearing out the app.xaml and app.xaml.cs files in leu of the bootstrapper.

Jul 20, 2011 at 8:56 PM

Thanks for pointing out the procedure to run with 7.1 too.