c# - SAP 中间件连接器错误
问题描述
我正在开发一个使用 SAP AG(版本 3.0.2)的 SAP.Middleware.Connector 的应用程序。
此应用程序在后台执行 RFC(使用 Task.Run),但几分钟后,应用程序崩溃,显示此图像中的堆栈跟踪。
DefaultDomain 中未捕获的异常,堆栈跟踪:System.UnhandledExceptionEventArgs
未处理的异常:System.InvalidOperationException:集合已修改;枚举操作可能无法执行。
在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource 资源) 在 System.Collections.Generic.Dictionary'2.KeyCollection.Enumerator.MoveNext() 在 SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(Object state) 在 System.Threading.TimerQueueTimer.CallCallbackInContext (对象状态)在 System.Threading.Executioncontext.RunInternal(ExecutionContext executionContext, ContextCallback, Object state, Boolean preserveSyncCtx) 在 System.Threading.Executioncontext.Run(ExecutionContext executionContext, ContextCallback, Object state, Boolean preserveSyncCtx) 在 System.Threading.TimerQueueTimer .CallCallback() 在 System.Threading.TimerQueueTimer.Fire() 在 System.Threading.TimerQueueTimer.FireNextTimers() 在 System.Threading.TimerQueueTimer.AppDomainTimerCallback()
这是 RFC 执行的代码:
return Task.Run(() =>
ConexionSAP cSap = new ConexionSAP();
cSap.ConectaSAP();
RfcDestination rfcDest = RfcDestinationManager.GetDestination(cSap.rfc);
RfcRepository rfcRep = rfcDest.Repository;
IRfcFunction function;
function = rfcRep.CreateFunction("XXXNAMEOFTHEFUNCTIONXXX");
//import parameters
RfcSessionManager.BeginContext(rfcDest);
function.Invoke(rfcDest);
//export parameters
RfcSessionManager.EndContext(rfcDest);
});
拜托,你能帮忙吗?
解决方案
谢谢您的帮助!
我正在回答这个问题。如果您在Thread上使用BeginContext和EndContext,连接器将尝试更新连接,但现在包含连接的线程已经消失,导致错误,Collection 已修改;枚举操作可能无法执行。
解决方案是删除BeginContext和EndContext行,一切正常。
推荐阅读
- c# - WPF XAML 文件中的 ObjectDataProvider.ConstructorParameters 疑难解答
- python - 在 pandas 数据框中从“年-月-日”格式中删除年份
- python - python - 将geopandas与python一起使用时如何使形状文件中的线条更粗?
- r - 在 r 中的组条件下从另一个数据帧中找到最接近的对值
- ruby-on-rails - Rails 5 中单个页面上的多个 Ajax 链接
- mongodb - 查询此文档的正确方法是什么?(如果索引正确)
- javascript - 如何正确地将来自多个嵌套查询的数据映射到所需的对象。反应/火力基地
- sql - 是否有一个 sql 函数可以查看输出并判断一个单元格和它上面的单元格是否相等?
- c - 是否有将读/写功能标记为线程安全功能的官方文档?
- visual-studio-code - VS Code 状态栏左侧的 >< 图标是什么?