Q:

Why do I get an InteropServices.COMException when attempting to launch QTP from C#?

This question is a follow-up to the one at Can I use a language other than VBScript to programmatically execute QTP Tests?. I have a C# (.Net 2.0) program which creates an instance of QuickTest.Application and launches QuickTest Professional (version 10.0). All my development testing worked well.
This morning, I attempted to execute the program from a test machine without the development environment (SharpDevelop 2.2.1). I received an error attempting to execute the program when I double-clicked the Windows icon. The console window flashed too quickly to see what it was, so I dropped down to a command prompt and executed the program from there. Everything worked fine. On the second attempted program launch, and all subsequent ones, I receive a System.Runtime.InteropServices.COMException which seems to be caused by the COM object throwing an RPC_E_SERVERFAULT. The function in question is 
virtual public QuickTest.Application LaunchQuickTestPro()
{
    QuickTest.Application qtpApp = new QuickTest.Application();
    qtpApp.Launch();
    qtpApp.Visible = false;
    return qtpApp;
}

and the qtpApp.Launch(); line is throwing the exception.
I'm at a complete loss as to what could be wrong. It works fine on the dev machine and worked fine once on the test machine. Rebooting between attempts seems to do no good. I'm fairly new to C#, .NET, and COM, so was hoping someone more experienced here might have seen this before. I'm probably missing something simple.
UPDATE: I have discovered this morning, after a reboot, that the Debug build works fine on the test machine (no development environment), but the Release build does not. I am going to try rebuilding and redeploying. Anyone have a suggestion for build options to examine for the Release build?
UPDATE2: It appears that both releases (Debug and Release) work correctly after a fresh reboot. If I try and launch either a second time, I get the error. I've added part of my Main() method and my ExitQTP() method below.
I'm wondering if part of the problem is my misunderstanding how ref should be used. However, the code does work every time when run in the IDE (SharpDevelop 2.2.1).
It does appear that something is not being properly cleaned up after the first run, but I don't know what. Looking at the task monitor, the QTP* processes go away as I expect them to. I think there may be a third process that is causing the problem, but haven't been able to isolate what that is,
    //Program starts here
    [STAThread]
    public static void Main(string[] args)
    {      
        string configFileName = 
            ConfigurationManager.AppSettings.Get("TestPathsConfigFile");

        TextReader configFile = new StreamReader(configFileName);
        QTPLauncher launcher = new QTPLauncher();
        string testName = null; 
        try
        {
            Debug.WriteLine("Creating QuickTest.Application object...");
            QuickTest.Application qtpApp = launcher.LaunchQuickTestPro();
            Debug.WriteLine("Successfully created QuickTest.Application object...");

            while((testName = configFile.ReadLine()) != null)
            {
                if((testName != string.Empty) &&
                   (!(testName.TrimStart()).StartsWith(COMMENT_START)))
                {
                    Debug.WriteLine(testName);

                    launcher.ExecuteQTPTest(testName, ref qtpApp);

                }
            } 

            configFile.Close(); 

           ... //code unrelated to problem removed.

            configFile = null;
            launcher.ExitQTP(ref qtpApp);
        }
        catch(System.Runtime.InteropServices.COMException ce)
        {
            Console.Error.WriteLine(ce.StackTrace);
        }
    }

//Exits QTP
virtual public void ExitQTP(ref QuickTest.Application qtpApp)
{
    qtpApp.Quit();
    qtpApp = null;
}

A:

I suspect the issue is that you are not properly closing (quitting) your QT app instance (if you check your task manager you may see it running) so the subsequent runs fail to initialize properly.
There is a decent blog post where Grant Holliday automates QT for running under Team Build.  Many of the same principles would apply.
http://ozgrant.com/2008/02/28/running-hp-quicktest-professional-ui-tests-with-team-build/
If that's not the issue you'll need to provide more details about what you do with the QT application object.

