简体   繁体   English

为什么我在尝试从 C# 启动 QTP 时收到 InteropServices.COMException?

[英]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?这个问题是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).我有一个 C# (.Net 2.0) 程序,它创建一个 QuickTest.Application 实例并启动 QuickTest Professional(版本 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).今天早上,我尝试在没有开发环境(SharpDevelop 2.2.1)的测试机上执行程序。 I received an error attempting to execute the program when I double-clicked the Windows icon.当我双击 Windows 图标时,尝试执行程序时收到错误消息。 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.控制台 window 闪烁得太快,看不清它是什么,所以我下降到命令提示符并从那里执行程序。 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 .在第二次尝试启动程序以及所有后续程序时,我收到一个System.Runtime.InteropServices.COMException ,这似乎是由 COM object 抛出RPC_E_SERVERFAULT引起的。 The function in question is有问题的 function 是

virtual public QuickTest.Application LaunchQuickTestPro()
{
    QuickTest.Application qtpApp = new QuickTest.Application();
    qtpApp.Launch();
    qtpApp.Visible = false;
    return qtpApp;
}

and the qtpApp.Launch();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.我是 C#、.NET 和 COM 的新手,所以我希望这里更有经验的人可能以前见过这个。 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. UPDATE2 :看起来两个版本(调试和发布)在重新启动后都可以正常工作。 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.我在下面添加了我的Main()方法的一部分和我的ExitQTP()方法。

I'm wondering if part of the problem is my misunderstanding how ref should be used.我想知道问题的一部分是否是我误解了ref应该如何使用。 However, the code does work every time when run in the IDE (SharpDevelop 2.2.1).但是,代码在 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.查看任务监视器,QTP* 按照我的预期处理了 go。 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;
}

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.我怀疑问题是你没有正确关闭(退出)你的 QT 应用程序实例(如果你检查你的任务管理器你可能会看到它正在运行)所以后续运行无法正确初始化。

There is a decent blog post where Grant Holliday automates QT for running under Team Build.有一篇不错的博客文章,其中 Grant Holliday 自动化 QT 以在 Team Build 下运行。 Many of the same principles would apply.许多相同的原则将适用。

http://ozgrant.com/2008/02/28/running-hp-quicktest-professional-ui-tests-with-team-build/ 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.如果这不是问题,您需要提供有关您使用 QT 应用程序 object 执行的操作的更多详细信息。

Use the following:使用以下内容:

Object oQTPapp;

oQTPapp = Server.CreateObject("QuickTest.Application");

Application qtpApp = (Application) oQTPapp;

Hopefully it will resolve your problem.希望它能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# AutoIt InteropServices.COMException 错误 - C# AutoIt InteropServices.COMException error 为什么使用此代码会得到“ InteropServices.COMException / ForwardCallToInvokeMember”? - Why would I get, “InteropServices.COMException / ForwardCallToInvokeMember” with this code? com 异常 excel InteropServices.COMException - c# - com exception excel InteropServices.COMException - c# 将项目添加到 ObservableCollection 时出现 InteropServices.COMException - InteropServices.COMException when adding item to ObservableCollection InteropServices.COMException - InteropServices.COMException 从ASP MVC控制器运行Word时保持获取InteropServices.COMException - Keep Getting InteropServices.COMException when running Word from ASP MVC Controller 如何在不安装Excel的情况下修复InteropServices.COMException? - How can I fix InteropServices.COMException without installing Excel? Excel中interopServices C#的COMException - COMException with interopServices C# in Excel 从页面调用静态异步方法导致 InteropServices.COMException 错误 - Calling a static async method from a Page results in InteropServices.COMException error 间歇性的“ InteropServices.COMException / ForwardCallToInvokeMember”在范围单元格上访问Value2 - Intermittent “InteropServices.COMException / ForwardCallToInvokeMember” accessing Value2 on Range cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM