windows phone 7

After moving some files my Windows Phone Project Throws a XamlParseException


I am not sure if this is an known issue for Microsoft, but at least I am aware of this. However this is the first time I am gonna document it. Since it can be very frustrating

The Problem

I want to reorganize the files in my Windows Phone Project in order to follow our implementation of MVVM, moreover we have decided that resx file will live in their own assembly project. However, once I move the Resource file to an external assembly the application just thrown an XamlParseException even though the reference in XAML is totally correct.

REMARKS
XamlParseExceptions may be thrown by other reasons. It is important to realize that I knew I moved the RESX file to a different assembly and before that everything was working. Certainly I updated the reference to the new assembly, and the exception was still being thrown. That is why this is a tricky issue.

The solution

It took some time to me to noticed, but somehow the project that contains the RESX file cannot contain a dot (.) character in its assembly name. If it happens then XAML parse will throw a XamlParserException even though the reference to the assembly is correct. The error message may contain something like this:

System.Windows.Markup.XamlParseException occurred
  HResult=-2146233087
  Message=Unknown parser error: Scanner 2147500037. [Line: 10 Position: 126]
  Source=System.Windows
  LineNumber=10
  LinePosition=126
  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at MyApp.App.InitializeComponent()
       at MyApp.App..ctor()
  InnerException: 

Taking a look at the location where I was loading the Resource it was this:

<Application
    x:Class="MyApp.App"
    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">

    <!--Application Resources-->
    <Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:MyApp;assembly=MyApp.WindowsPhone8.Resources" x:Key="LocalizedStrings"/>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>

The line one of my projects generates an assembly named: ‘MyApp.WindowsPhone8.Resources’, in order to resolve the issue I only have to update the generated assembly name to be ‘MyApp_WindowsPhone8_Resources’ and then update the proper reference in the XAML. For example:

        <local:LocalizedStrings xmlns:local="clr-namespace:MyApp;assembly=MyApp_WindowsPhone8_Resources" x:Key="LocalizedStrings"/>

After performing this change your app should work normally.

WP7: Libraries about Cloud services (Azure, AWS, Hawaii), Toolkits (WP7) and more


Hi,

I’d like to share with you some of the libraries that I’ve been reading (or using in some cases) in WP7 projects.

Silverlight for Windows Phone Toolkit @ http://silverlight.codeplex.com/
This might be the only one that should be mandatory in your WP7 project. This library contains a set of controls to enhance the WP7 experience by adding custom animations and custom controls. 

Reactive Extensions for Windows Phone 7 @ http://msdn.microsoft.com/en-us/data/gg577610
This library helps you to control Asynchronous tasks or events. It’s like creating pipes based on asynchronous events.

Hawaii Cloud Services SDK for Windows Phone 7 @ http://research.microsoft.com/en-us/um/redmond/projects/hawaii/students/
This particular project is for non-commercial projects, and at this time it’s free because it’s a research project. This project lets use use the cloud services in order to have services such as: Speech to Text (aka voice recognition), OCR among others.

[watwp] Windows Azure Toolkit for Windows Phone 7 @ http://watwp.codeplex.com/
(http://channel9.msdn.com/posts/Getting-Started-with-the-Windows-Azure-Toolkit-for-Windows-Phone-7-v12)
A simple way to access Azure services thru your WP7.

Amazon Web Services SDK for Windows Phone 7 @ https://github.com/Microsoft-Interop/AWS-SDK-for-WP (http://channel9.msdn.com/Blogs/Interoperability/Getting-Started-with-the-AWS-SDK-for-Windows-Phone)
Well for those how have worked with AWS, this library will simplify some of the tasks accessing services such as S3 (which is web storage).

[PAARC] Phone as Remote Control @ http://paarc.codeplex.com/ (http://channel9.msdn.com/coding4fun/blog/Getting-your-WP7—Desktop-integration-out-of-park-with-PAARC-the-Phone-as-a-Remote-Control-library)
I really like this one. It’s just a simple (and efficient) mechanism to establish a connection between your phone and your PC. Thus, the phone will work as a input device, and the PC has already a running a service which will report all the input generated by the phone.

Zune Web API @ http://channel9.msdn.com/coding4fun/articles/Using-the-Zune-Web-API-on-Windows-Phone-7
This is not exactly an SDK, but it will help you to get information from your Zune account 😉

Best regards,
Herber