Catel unit test exception in WinRT project.

Topics: Questions
Feb 14, 2013 at 6:47 PM
Hello,

I'm just starting out with Catel in a Windows RT application and I have run into an issue.

I'm running into an exception when trying run a unit test against a Catel ViewModel. If I make a new Catel Win8 project and also make a Win8 Unit Test project, add a reference to the Win8 project and try instantiating the MainPageViewModel, I receive the following exception:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: 
System.TypeInitializationException: The type initializer for 'Catel.Reflection.ReflectionExtensions' threw an exception. ---> System.Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
    at Windows.UI.Xaml.DispatcherTimer..ctor()
   at Catel.Caching.CacheStorage`2..ctor(Boolean allowNullValues)
   at Catel.Reflection.ReflectionExtensions..cctor()
 --- End of inner exception stack trace ---
    at Catel.Reflection.ReflectionExtensions.GetConstructorsEx(Type type)
   at Catel.IoC.TypeFactory.CreateInstance(Type typeToConstruct)
   at Catel.IoC.TypeFactory.CreateInstance()
   at UnitTests.UnitTest1.TestMethod1() in UnitTest1.cs: line 16
Is there a different way of creating an instance that should be used in this case? I've tried just making a new instance and using the TypeFactory CreateInstance method with the same result.
Coordinator
Feb 14, 2013 at 7:02 PM
Interesting. Do you have a very small repro? Then I can fix it.
Feb 14, 2013 at 9:03 PM
Sure. Its pretty much just a new project and a unit test project, but this is what I have: https://bitbucket.org/zacharybussey/testwin8catel/downloads
Coordinator
Feb 15, 2013 at 3:51 PM
Issue is solved, sorry for the inconvenience. I wrote a custom timer which does not use the DispatcherTimer because it can only be created on a UI thread.
Feb 18, 2013 at 5:26 PM
Thank you for addressing this so quickly. I've downloaded the latest and everything appears to be working correctly.