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
Please sign in to leave a comment.
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
Thanks, it works!
I tried something similar earlier but must have made a mistake :)
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.
Hello,
Web mirroring issues, probably. See news://news.intellij.net/76a2bd0b15102a8ca436d9a00528a@news.intellij.net
—
Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”
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/
What about xUnit STA?