Erro C # “Tentativa de ler ou gravar memória protegida” ou “Componente externo lançou uma exceção”
Tenho um programa C # (estrutura de destino .NET 4.0) que faz chamadas para objetos COM (código não gerenciado), todos os objetos gerenciados corretamente, destruídos quando não são mais necessários et
Tenho também poucas manipulações de exceções, blocos try / catch sem exceções personalizadas. No entanto, algumas vezes este programa falhou, funciona na maioria das vezes, comportamento aleatório. Os rastreamentos de pilha também variam, por exemplo:
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, Linha 17: Application.Run (new 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:
stou em estágio de isolamento para descobrir a raiz desse err
Você tem alguma sugestão desse erro? Quaisquer sugestões sobre como capturar essas exceções e sair normalmentObrigado pela ajuda