如何使用C#调用qtp的对象库lib

时间:2011-10-18 02:34:02

标签: c# qtp

我最近遇到了一个问题。我想使用C#调用QTP的Object Repository Lib,但它不起作用。 代码:

REPOSITORYUTILLib.ObjectRepositoryUtil or = new REPOSITORYUTILLib.ObjectRepositoryUtil();
or.Load(@"C:\Repository.tsr");
or.GetAllObjects();

但是当程序运行到System.InvalidCastException时我收到or.GetAllObjects();,我在这里看不到任何强制转换操作,我怎么能得到这样的异常? 有没有人有想法?感谢。

这是stacktrace:

    mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(objectarg,System.Type    paramType) + 0xe7 bytes   
    mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(System.Runtime.Remoting.Messaging.IMessage msg, object[] outArgs, object returnValue) + 0x88 bytes    
mscorlib.dll!System.RuntimeType.ForwardCallToInvokeMember(string memberName, System.Reflection.BindingFlags flags, object target, int[] aWrapperTypes, ref System.Runtime.Remoting.Proxies.MessageData msgData) + 0x26e bytes

test.exe!test.test.Main() lines 14 + 0xf bytes  C#

mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile,     System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6d bytes    
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2a bytes  
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x63 bytes   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes    
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x2c bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes   

1 个答案:

答案 0 :(得分:1)

可以使用反射访问QTP对象存储库。使用反射将有助于消除上述错误。