InvalidOperationException:撤消操作遇到的上下文与相应设置操作中应用的上下文不同

发布于 2024-09-01 17:39:03 字数 2272 浏览 0 评论 0原文

我遇到以下异常:

Exception Type: System.InvalidOperationException  
Exception Message: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).  
Exception Stack:   at System.Threading.SynchronizationContextSwitcher.Undo()  
at System.Threading.ExecutionContextSwitcher.Undo()  
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)  
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)  
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)  
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Net.ContextAwareResult.Complete(IntPtr userToken)  
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)  
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)  
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)  
Exception Source: mscorlib  
Exception TargetSite.Name: Undo  
Exception HelpLink:  

该应用程序是 Visual Studio 2005 (.Net 2.0) 控制台应用程序。它是一个用于多个 TCP/IP 连接的服务器,执行异步套接字读取和同步套接字写入。

在寻找答案时,我遇到了 这篇文章讨论了对 Application.Doevents() 的调用,我在代码中没有使用它。

我还找到了这篇文章< /a> 其中有一个与 Component 相关的解决方案,我也没有在我的代码中使用它。该应用程序确实引用了我创建的包含自定义用户控件和组件的库,但应用程序并未使用它们。

问: 是什么原因导致这种情况发生以及如何防止这种情况再次发生? 或者一个更现实的问题:这个异常实际上意味着什么?在这种情况下如何定义“上下文”?

任何可以帮助我了解正在发生的事情的信息都将非常感激。

I got the following exception:

Exception Type: System.InvalidOperationException  
Exception Message: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).  
Exception Stack:   at System.Threading.SynchronizationContextSwitcher.Undo()  
at System.Threading.ExecutionContextSwitcher.Undo()  
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)  
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)  
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)  
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Net.ContextAwareResult.Complete(IntPtr userToken)  
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)  
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)  
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)  
Exception Source: mscorlib  
Exception TargetSite.Name: Undo  
Exception HelpLink:  

The application is a Visual Studio 2005 (.Net 2.0) console application. It is a server for multiple TCP/IP connections, doing asynchronous socket reads and synchronous socket writes.

In searching for an answer I came across this post which talks about a call to Application.Doevents() which I don't use in my code.

I also found this post which has a resolution involved with Component which I also don't use in my code. The application does reference a library that I created that contains custom user controls and components, but they are not being used by the application.

Question: What caused this to happen and how do I prevent this from happening again?
Or a more realistic question: What does this exception actually mean? How is "context" defined in this situation?

Anything that can help me understand what is going on would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轻拂→两袖风尘 2024-09-08 17:39:03

context 指的是“线程上下文”,与您的代码没有任何关系。
然而,这是 .net 的内部问题,可能仅限于 beta 版本

context refers to as "Thread Context" and is not in any way related to your code.
However it is an internal issue with .net which could be only limited to beta editions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文