【发布时间】:2022-10-20 18:19:12
【问题描述】:
我使用下面的代码从 SAP GUI 7.60 版本中的任何可用连接获取 SAP GUI 会话,但最近升级到 7.70 版本,它没有获取会话。
//Take the control of SAPGUI Script.
_sapROTWrapper = new CSapROTWrapper();
_SapGuilRot = _sapROTWrapper.GetROTEntry("SAPGUI");
_engine = _SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod,
null, _SapGuilRot, null);
_SAPApp = _engine as GuiApplication;
//Get the SAP connection count to check how many open connections are.
var count = _SAPApp.Connections.Count;
if (count > 0)
{
//More than one connections are there.
var connections = _SAPApp.Connections;
//Get all connections and iterate through all.
foreach (GuiConnection connection in connections)
{
_repSession = connection.Children.ElementAt(0) as GuiSession;
}
}
升级此行后未显示任何元素 _repSession = connection.Children.ElementAt(0) as GuiSession; 并抛出错误
The enumerator of the collection cannot find an element with the specified index.
尽管会话 connection.Children.Count 已经运行,但返回 0 个会话。
任何面临相同问题或有任何解决方案的人。感谢你的帮助。
【问题讨论】: