我已使用远程代理为我的自定义控件实现了Coded-UI外部插件支持,我的实现细节如下所述,
应用
public partial class Form1 : ControlTestApplication
{
#region "Constructor"
public Form1()
{
InitializeComponent();
}
}
实施
public class ControlTestApplication : Form, IObserver
{
protected override void OnLoad(EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
this.channel = new IpcChannel("CustomControl");
ChannelServices.RegisterChannel(this.channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(InteropService), "ControlTestService", WellKnownObjectMode.Singleton);
Cache.Attach(this);
base.OnLoad(e);
}
}
internal class Communicator
{
private static IControlInteropService thisInstance;
/// <summary>
/// Gets the instance of the test service.
/// </summary>
internal static IControlInteropService Instance
{
get
{
if (thisInstance == null)
{
thisInstance = (IControlInteropService)Activator.GetObject(typeof(IControlInteropService), "ipc://Control/ControlTestService");
}
return thisInstance;
}
}
}
现在,我尝试使用以下代码从另一个dll使用IContrlInteropService(InteropService)接口获取我的控制信息,
public sealed class ControlTechnologyManager : UITechnologyManager
{
public override IUITechnologyElement GetElementFromPoint(int pointX, int pointY)
{
var windowHandle = Utilities.WindowFromPoint(pointX, pointY);
return this.GetControlElement(windowHandle, InteropService.GetElementFromPoint(int pointX, int pointY));
}
}
抛出了无效的强制转换异常。请找到以下堆栈跟踪详细信息,
System.InvalidCastException未被用户代码处理 HResult = -2147467262 Message =返回参数的类型无效。 Source = mscorlib StackTrace:at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(对象 arg,键入paramType)at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(即时聊天 msg,Object [] outArgs,Object returnValue)at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)at CustomControl.WF.UITest.Services.IControlInteropService.GetElementFromPoint(的Int32 pointX,Int32 pointY)at CustomControl.WF.UITest.ControlTechnologyManager.GetElementFromPoint(的Int32 pointX,Int32 pointY)在d:\ svn \ studio \ src \ trunk \ Windows \ Control.Windows \ UITest \ Src \ SyncControlExtensionProvider \ ControlTechnologyManager.cs:line 112点 Microsoft.VisualStudio.TestTools.UITest.Extension.UITechnologyManager.GetElementFromPoint(的Int32 pointX,Int32 pointY,AutomationElement ceilingElement)at Microsoft.VisualStudio.TestTools.UITest.Framework.AbstractUITestService.GetTechnologyElementsFromRawElementsHierachy(List
1 managersHierarchy, List
1 rawElementsGroup,Int32 pointX,Int32 pointY,Boolean usePoints)at Microsoft.VisualStudio.TestTools.UITest.Framework.AbstractUITestService.GetTechnologyElementFromAE(AutomationElement element,Int32 pointX,Int32 pointY,Boolean usePoints)at Microsoft.VisualStudio.TestTools.UITest.Framework.AbstractUITestService.GetElementFromPoint(的Int32 pointX,Int32 pointY)InnerException:
注意: 这个实现在VS2012中运行良好。仅在VS2013,VS2015和VS2017中才会出现此问题。
我已经部分实现了对下面附带的按钮的外部插件支持,
https://drive.google.com/open?id=0B6mYuvHmZAe-RjRJeUN5S2hzX28
您可以按照以下步骤重现该问题,
C:\ Program Files(x86)\ Common Files \ microsoft shared \ VSTT \ 12.0 \ UITestExtensionPackages
C:\ Program Files(x86)\ Microsoft Visual Studio 12 \ Common7 \ IDE \ PublicAssemblies
C:\ Program Files(x86)\ Microsoft Visual Studio 12 \ Common7 \ IDE \ PrivateAssemblies
当我尝试使用System.RunTime.Remoting.Proxies从另一个dll [Button.TestService]获取控件信息时,会出现此问题。
所以,请建议我解决这个问题。
提前致谢,