Usuário com melhor resposta
Exceção no SaveFileDialog

Pergunta
-
A dúvida é o seguinte:
Numa aplicação bem básica do SaveFileDialog o programa gera a seguinte exceção:
"Tentativa de leitura ou gravação em memória protegida. Normalmente, isso é uma indicação de que outra memória está danificada".
O que me parece muito estranho é que a exceção é "unhandled" mesmo com bloco try/catch, e quando o binário é executado o software trava mesmo com bloco try/catch.
Segue o pedaço do código:
Try
Dim DialogoSalvarArquivo As New SaveFileDialog()
Dim NomeArquivo As String = "Relatório Geral de Chamadas"
DialogoSalvarArquivo.Filter = "Arquivo PDF|"
DialogoSalvarArquivo.FileName = NomeArquivo
If DialogoSalvarArquivo.ShowDialog() <> Windows.Forms.DialogResult.OK Then
MsgBox("Emissão de Relatório Cancelada")
Return
End If
Catch ex As Exception
UtilMsgBox.ExibaMsgAdvertencia(ex.ToString())
End TryAlguém por favor poderia me dar uma ajuda <3
Desde já grato!
-----------------------------------
Detalhes da Exceção:
System.AccessViolationException was unhandled
HResult=-2147467261
Message=Tentativa de leitura ou gravação em memória protegida. Normalmente, isso é uma indicação de que outra memória está danificada.
Source=System.Windows.Forms
StackTrace:
em System.Windows.Forms.FileDialogNative.IFileDialog.Show(IntPtr parent)
em System.Windows.Forms.FileDialog.RunDialogVista(IntPtr hWndOwner)
em System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
em Pctel_Supervisor_Desktop.ControladorDeTelaDeRelatorios.ExportaRelatorioGeral(Int32 Formato) na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\ControladoresDeTela\ControladorDeTelaDeRelatorios.vb:linha 138
em Pctel_Supervisor_Desktop.Window2.btoExportarCSV_Click(Object sender, RoutedEventArgs e) na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\Formularios\GeraRelatorios.xaml.vb:linha 76
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.Controls.Button.OnClick()
em System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
em System.Windows.Input.InputManager.ProcessStagingArea()
em System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
em System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
em System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Window.ShowHelper(Object booleanBox)
em System.Windows.Window.ShowDialog()
em Pctel_Supervisor_Desktop.UtilAbreTela.AbraTelaRelatorios() na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\Utilidades\UtilAbreTela.vb:linha 210
em Pctel_Supervisor_Desktop.Principal.AbraJaneRelatorios() na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\Formularios\Principal.xaml.vb:linha 370
em Pctel_Supervisor_Desktop.Principal._Lambda$__8(Object a0, RoutedEventArgs a1) na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\obj\x86\Debug\Formularios\Principal.g.vb:linha 294
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.DispatcherOperation.InvokeImpl()
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em System.Windows.Threading.DispatcherOperation.Invoke()
em System.Windows.Threading.Dispatcher.ProcessQueue()
em System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Application.RunInternal(Window window)
em System.Windows.Application.Run()
em Pctel_Supervisor_Desktop.Application.Main() na D:\PCTEL_DEV\Software\Pctel_Supervisor_Desktop_Protocolo\Codigo\Pctel_Supervisor_Desktop\Pctel_Supervisor_Desktop\obj\x86\Debug\Application.g.vb:linha 66
em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em System.Threading.ThreadHelper.ThreadStart()
InnerException:
Respostas
-
Olá Attyla!
Você está utilizando alguma conexão OleDb no seu projeto? Tem um bug em um driver do OleDb que causa esse comportamento estranho de AccessViolationException disparado pelo SaveFileDialog.. Tem um hotfix para esse bug e você encontra mais informações aqui:
OleDB operations cause AccessViolationException during SaveFileDialog
E o fato do seu bloco try-catch não estar pegando essa exception é porque exceções desse tipo são marcadas pelo .NET Framework 4 (ou superior) como exceções não recuperáveis.. Ou seja, uma vez que uma exception dessa é disparada, não tem bloco try-catch que faça o processo se recuperar..
Esse comportamento foi introduzido no .NET Framework 4 e tem algumas maneiras de contornar isso, que você pode encontrar neste link:
How to handle AccessViolationException
Abraço!
André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima- Marcado como Resposta Attyla Fellipe sexta-feira, 4 de novembro de 2016 10:29
Todas as Respostas
-
Qual versão do .Net Framework seu projeto está usando?
If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer". Se achou este post útil, por favor clique em "Votar como útil". Se por um acaso respondeu sua dúvida, lembre de "Marcar como Resposta".
-
Olá Attyla!
Você está utilizando alguma conexão OleDb no seu projeto? Tem um bug em um driver do OleDb que causa esse comportamento estranho de AccessViolationException disparado pelo SaveFileDialog.. Tem um hotfix para esse bug e você encontra mais informações aqui:
OleDB operations cause AccessViolationException during SaveFileDialog
E o fato do seu bloco try-catch não estar pegando essa exception é porque exceções desse tipo são marcadas pelo .NET Framework 4 (ou superior) como exceções não recuperáveis.. Ou seja, uma vez que uma exception dessa é disparada, não tem bloco try-catch que faça o processo se recuperar..
Esse comportamento foi introduzido no .NET Framework 4 e tem algumas maneiras de contornar isso, que você pode encontrar neste link:
How to handle AccessViolationException
Abraço!
André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima- Marcado como Resposta Attyla Fellipe sexta-feira, 4 de novembro de 2016 10:29
-
-
Magina Attyla! Fico feliz que o hotfix tenha resolvido o seu problema.. Qualquer coisa entre em contato novamente!
Abraço!
André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima