WP7: Getting Started with UnitTest Platform: XamlParseException

I want to add Unit Tests to my WP7 project. I went for tutrials at http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7 to get started with unit tests. But I can’t make it work.

I followed all the steps from the tutorial and created basictests.

But as soon as I want to start the project, Visual Studio gives an error message:

XamlParseException event occurred. Cannot find resource with name / key typeNameConverter [Line: 47 Position: 24]

Line 47 refers to the original CreateTestPage page:

private void MainPage_Loaded(object sender, RoutedEventArgs e) { SystemTray.IsVisible = false; Line47: var testPage = UnitTestSystem.CreateTestPage() as IMobileTestPage; BackKeyPress += (x, xe) => xe.Cancel = testPage.NavigateBack(); (Application.Current.RootVisual as PhoneApplicationFrame).Content = testPage; } 

I hope you help me! thanks!

+4
source share
5 answers

You are probably using the Jeff Willcox toolkit for Windows Phone 7. If you want to run it under the new Windows Phone, try using the new toolkit, just like me. Try using the Jeff Willcox toolkit for Windows Phone 7.5 (Mango). Get it here: http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/ Good luck.

+4
source

I came across this yesterday and found that App.xaml was not configured correctly. Using guesswork (i.e., which interfaces implements IValueConverter ?), I found this solution that seems to work very well.

First add this namespace to the <Application> namespace:

 xmlns:Client="clr-namespace:Microsoft.Silverlight.Testing.Client;assembly=Microsoft.Silverlight.Testing"> 

Then add this to <Application> :

 <Application.Resources> <Client:TypeNameVisibilityConverter x:Name="typeNameConverter" /> <Client:FontWeightConverter x:Name="fontWeightConverter" /> </Application.Resources> 

I hope this is useful to someone.

I can confirm that the Michael Dumont solution also works, but you cannot view the details of the test run that are annoying when you try to view information about broken tests when you do not have a debugger connected for any reason.

+4
source

Make sure your Unit test project is for .Net Framework 3.0 or 3.5 and uses the Mango-compatible Unit Test Framework Assemblies created by Jeff Wilcox. I had the same error when project for .Net Framework 4.0.

+2
source

I also got this error and ran the ValueConverters that he was looking for and was able to successfully get the working environment.

App.xaml

 <!--Application Resources--> <Application.Resources> <s:typeNameConverter x:Name="typeNameConverter"></s:typeNameConverter> <s:fontWeightConverter x:Name="fontWeightConverter"></s:fontWeightConverter> </Application.Resources> 

Value Converters

 public class typeNameConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class fontWeightConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 
+1
source

And this exception applies to XAML in TestPage. Thus, you are sending the wrong code.

In any case, the error is very clear. The declared typeNameConverter in your XAML. Most likely, you forgot to add a reference to the assembly, declaring it, or update xmlns so that it points to another assembly, and not just to a different namespace.

0
source

All Articles