Statlight throwing resource not found exception when Unit testing View using silverlight 4 Unit test application

Sep 27, 2010 at 8:18 AM
Edited Sep 27, 2010 at 8:40 AM


I am trying to unit test my view for bindings using Silverlight 4 unit test application.I have made a test project and writen a unit test for testing my views .The views are loaded asynchronously .When i am testing the  test cases using VS 2010 IDE the test case run very fine.I am using MS Build for running the unit test.

But when i use Statlight for testing my XAP which contains the test it gives me error that staticresorces defined in my view cant be find as in the error is Cannot find resource with name key "abc".

These esources are defined in my shell of application and i have added reference of the project in my Test application.

Also i have manually copied these resources in a resource dictionarty in athe App.xaml of the test project.

Kindly let me know itf i am missing something.

Sep 27, 2010 at 1:19 PM

What is the exception you are seeing? (Stack trace... etc)

One thing to try is run statlight with the --webserveronly flag. Copy/paste the hyperlink it gives you into firefox (with firebug installed) monitor the network traffic.

Sep 28, 2010 at 6:27 AM
Edited Sep 28, 2010 at 8:54 AM

Hi staxmanade,

Thnks for your reply.


Please find below the stack trace:

XamlPareseException was unhandled
Cannot find a resource with Name/Key boolToCommandVisibilityConverter [Line 29:Position 109]

at System.Windows.Application.LoadComponent(object component,URi resourceLocator)
at View.InitializeComponent()

What i think is that when the my control or the view whic i need to test is getting loaded its not able to find the static resources I have defined which are although part of application shell whose reference i have added in my test project.

Everything works very fine on debugging in VS 2010.

Kindly let me know if i can send you a sample project with this problem .



Sep 28, 2010 at 2:18 PM

Checkout the following link I found by googling a few items in your most recent post.

Hope this helps.

If not - feel free to send over a link to a repro'd project and I'll take a look.

Sep 29, 2010 at 6:46 AM
Edited Sep 29, 2010 at 1:19 PM

Hi StaxMande,

The solution given in the above post helped.Thanks for the help.

The solution is as follows:

1)For asynchonous Unit test of views SilverLight 4 unit test framework the resource needs to be added in the test initialise method explicitly.

2)initially i had added them in App.xaml Merged dictionary of my test application which was working fine when debugged/executed using VS 2010 but Statlight was giving me error when ran using command prompt.

3)So suppose i have a resource in my XAP to be tested as booleanTovisibilityconvertor then it need to be added in the Test App using the following line

public void 
App.Current.Resources.Add("boolToVisibilityConverter", new BoolToVisibilityConverter 
3)Adding in the APp.xaml of the test didnt help and i still wonder why but adding the above line of code in Test class explicitly helped.
Sep 29, 2010 at 1:34 PM

I'm glad you figured it out. 

Just to clarify. StatLight is the host "App" in the Silverlight plugin. StatLight dynamically downloads and adds your assemblies into the appdomain. This means if you have any custom logic in you App.xaml.cs's app startup method - it will get bypassed and never executed because it's StatLight's App.xaml.cs code that's actually executed.

Hope this helps clarify.

Sep 29, 2010 at 2:52 PM

Ok thanks .

Got it.