Invalid cross-thread access

Aug 10, 2012 at 7:19 PM

I'm writing a tests for one of my models (FooModel) which depends on a CategoriesModel which uses a CollectionViewSource.  When I execute my test under AgUnit, construction of that CollectionViewSource is throwing an UnauthorizedAccessException complaining about cross-thread access:

Test method Test.FooModelTests.TestRemoveAfterAdd threw exception: System.UnauthorizedAccessException: Invalid cross-thread access

  • at MS.Internal.XcpImports.CheckThread()
  • at MS.Internal.ManagedPeerHelper.SetupManagedPeer(IManagedPeerBase managedPeer, ref NativeObjectSafeHandle nativeSafeHandle, UInt32 nativeTypeIndex, IntPtr constructDO, Nullable`1 isCustomType, Nullable`1 forceStrong)
  • at System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex, IntPtr constructDO)at System.Windows.Data.CollectionViewSource..ctor()
  • at ReferenceData.CategoriesModel..ctor() in CategoriesModel.cs: line 93
  • at FooModel..ctor() in FooModel.cs: line 44
  • at Tests.FooModelTests.TestRemoveAfterAdd() in ModelTests.cs: line 17

Has anyone ever encountered this?