C # error "Intentó leer o escribir memoria protegida" o "El componente externo ha producido una excepción"
Tengo un programa C # (target framework .NET 4.0) que realiza llamadas a objetos COM (código no administrado), todos los objetos administrados correctamente, destruidos cuando ya no son necesarios, etc.
Tengo también algunas excepciones manejador, trate / atrapar bloques sin excepciones personalizadas. Sin embargo, algunas veces este programa falla, funciona la mayoría de las veces, comportamiento aleatorio. Las trazas de pila también varían, por ejemplo:
System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at IndexerTester.Program.Main() in D:\Tester\Program.cs:line 17
InnerException:
In Program.cs, Línea 17: Application.Run (nuevo Form1 ());
System.Runtime.InteropServices.SEHException was unhandled
Message=External component has thrown an exception.
Source=System.Windows.Forms
ErrorCode=-2147467259
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at IndexerTester.Program.Main() in D:\Tester\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Estoy en una etapa de aislamiento para descubrir la raíz de este error.
¿Tiene alguna sugerencia de este error?Cualquier sugerencia sobre detectar estas excepciones y salir con gracia.Gracias por tu ayuda