InvalidCrossThreadAccess with nunit

Apr 20, 2011 at 11:07 AM

Hi,

 

I'm trying to test my ViewModel which inherits screen, but nunit is barfing with the following error when trying to construct my viewmodel :

System.TypeInitializationException : The type initializer for 'Caliburn.Micro.ConventionManager' threw an exception.  ----> System.UnauthorizedAccessException : [InvalidCrossThreadAccess] at Caliburn.Micro.ViewAware..ctor() at Caliburn.Micro.Screen..ctor() Orders\OrderViewModel.cs(19,0): 

My view model has nothing it it apart from inheriting Screen: 

public class OrderViewModel : Screen

{

}

Am using latest Caliburn (taken from codeplex last night).

 

Any help would be most appreciated !

Coordinator
Apr 20, 2011 at 1:29 PM

If you are running the Bootstrapper as part of your test suite, then get rid of that. It could be related. The only other thing I can think that might be causing it is XamlReader.Load which is called during the initialization of the ConventionManager. Can you send me a stripped-down sample that demonstrates the issue? I made some changes there very recently, so I may have introduced a bug. Feel free to email me at robertheisenberg at hotmail dot com Or, create an issue and attach the solution.

Apr 21, 2011 at 3:00 PM

Hi, I've created an issue : http://caliburnmicro.codeplex.com/workitem/103 with a reproducing project.

Look forward to your response,

Cheers,

Ben

Coordinator
Apr 21, 2011 at 5:21 PM

Great. I'll try to get a look at it this weekend. I have an idea what the problem is, so it should be easy to fix it.

Apr 21, 2011 at 5:27 PM

Rob, I checked with the debugger and I can confirm that, if the Bootstrapper is not initialized, the exception is raised by the XamlLoader.

I even tried initializing the Bootstrapper properly, but in that case it seems that the Silverlight environment causes some issues.

Coordinator
Apr 21, 2011 at 5:50 PM

Oops... It should be an easy fix at least. I'll just need to reorganize a few things.  

Apr 21, 2011 at 7:52 PM

Great, thanks for you help guys