Changing unit test runner thread state apartment to STA

Hi,
We have some code that uses XamlReader.Load, however when Resharper runs a test that exercises this code, it fails with the exception:

System.InvalidOperationException: The calling thread must be STA, because many UI components require this.

NUnit can be configured to run in an STA thread, however I don't see any similar way of doing this in Resharper. Is this possible? If so, how?

Many thanks,
Gerald

6 comments
Comment actions Permalink

Hello Gerald,

Create config file for test assembly with the following contents (or add
to existing):

Sincerely, Ilya Ryzhenkov JetBrains, Inc http://www.jetbrains.com "Develop with pleasure!" IR> Hi, IR> We have some code that uses XamlReader.Load, however when Resharper IR> runs a test that exercises this code, it fails with the exception: IR> System.InvalidOperationException: The calling thread must be STA, IR> because many UI components require this. IR> IR> NUnit can be configured to run in an STA thread, however I don't see IR> any similar way of doing this in Resharper. Is this possible? If IR> so, how? IR> IR> Many thanks, IR>]]> Gerald


0
Comment actions Permalink

Thanks, it works!
I tried something similar earlier but must have made a mistake :)

0
Comment actions Permalink

The answer to this question has been deleted - there are no "following contents" in the answer.
Can I suggest that you either put the contents back or mark this question as unanswered - because it is effectively unanswered to anyone who looks at it.

0
Comment actions Permalink

Hello,

The answer to this question has been deleted - there are no "following
contents" in the answer.


Web mirroring issues, probably. See news://news.intellij.net/76a2bd0b15102a8ca436d9a00528a@news.intellij.net


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

The news article linked to (apart from requiring a news reader) didn't include the configuration section and could therefore be confusing to those who wanted a single copy-paste solution.

I suggest following this article; you can copy the XML straight into a new app.config file (in the assembly of your tests) and you're done.
http://www.hedgate.net/articles/2007/01/08/instantiating-a-wpf-control-from-an-nunit-test/

0
Comment actions Permalink

What about xUnit STA?

0

Please sign in to leave a comment.