Dispatcher.CheckAccess() dies

Mar 26, 2012 at 1:16 PM

I'm using AgUnit, which in turn uses StatLight, to run some non-UI Silverlight unit tests.  Part of my code calls Deployment.Current.Dispatcher.CheckAccess().  That test is failing with the following exception:

[MyTest] threw exception: 
System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Deployment_GetCurrent(ref IntPtr pDeployment)
at System.Windows.Deployment.get_Current()
at MyCode.ThreadingSupport.ExecuteOnUiThread(Action executeHandler) in ThreadingSupport.cs: line 10

I searched the web and didn't find anyone else having this problem.

Also, this dies not occur when I run this directly using StatLight from the command line -- only in AgUnit.

Any ideas?

Mar 26, 2012 at 4:36 PM


This is probably because AgUnit runs StatLight in non-UI mode.

If you feel you're up to it, I advise you to check out AgUnit and play with the configuration options passed in to StatLight.
You can find them in this file (in the CreateStatLightInputOptions method):

Information to build AgUnit is on the main page: http://agunit.codeplex.com/. You have to run the build.bat file first before compiling from Visual Studio, this is required to build StatLight.

I'll try investigate the issue as soon as possible.



Mar 27, 2012 at 1:20 PM

When I ran StatLight directly from the command-line, I also ran in non-UI mode.  I have some libraries that assist in calling WCF services and need to be sure they're on the UI thread when completing.  So they call a utility method (borrowed and distilled from EntLib):

public static void ExecuteOnUiThread(Action executeHandler)
    if (Deployment.Current.Dispatcher.CheckAccess())

I didn't consider that to be something that required UI-mode testing, and in fact, doesn't appear to when running in StatLight directly.  My anemic understanding is that by not specifying "-b", I'm running it in non-UI mode (reinforced that my headless service account runs these tests under Jenkins without issue).

Is there something more explicit to toggling non-UI mode?

I'll be glad to tweak AgUnit source, but at this point, I'm uncertain of what tweak I would need to make.