First I started by creating an assembly to be used from NUnit GUI. Some tests failed without an obvious reason. After some research I understood that the COM apartment must be STAThread. The threading model must be set before the thread is started but I don't have access to NUnit GUI main thread from my assembly.
One possible solution to this problem is to transform the assembly into an EXE application that uses the NUnit framework like this:
[STAThread]When /nothread command line flag is used the tests are executed by the main thread which already has the right COM apartment properly set.
public static void Main(string[] args)
{
NUnit.ConsoleRunner.Runner.Main(
new string[] { System.AppDomain.CurrentDomain.BaseDirectory + "MyExe.exe", "/nothread" });
}
6 comments:
Hi!
There is also a nice solution to this problem posted at http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=1791 (I have tried it and it works for me).
An application configuration file (app.config) must be added to your VS project containing the following data:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
This will force NUnit to use STA threading model.
Thank you for sharing the solution!
Yes, thanks, the solution works well.
Alex K
You are welcome
hi there! I am new to the board and just wanted to introduce myself :)
Hi there and welcome aboard
Post a Comment