我正在爲.NET中的遷移過程中具有VB6應用程序的客戶端工作。.NET應用程序中的COM控件中的AccessViolationException
目前他們有一個.NET外殼,但在.NET中託管一些舊的VB6控件。 有我偶然發現了一個錯誤日誌發生這種情況時,他們在.NET異步從數據庫中提取一些數據,然後將數據轉發到一個COM組件來顯示它:
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).
Err Source: mscorlib
Err Type: System.InvalidOperationException
ERROR stack trace:
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.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
那麼下面的顯示出來日誌:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Err Source: mscorlib
Err Type: System.AccessViolationException
ERROR stack trace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at _Client's component that forwards calls to COM_
有沒有人遇到過這樣的事情?我如何解決它?
是的,組件是一個UI控件,它很可能是從其他線程更新的。不確定,因爲我還沒有看到代碼,只是得到了日誌。不過,我想我會得到其他異常,如果這確實是其他線程更新UI的問題,還是僅適用於.NET?不知道COM如何處理它。無論如何 - 我會嘗試你的建議。 –
糾正我,如果我錯了,但我相信你可以通過從不同的線程直接更新UI組件來破壞內存。 。 。 –