我的应用程序遇到了一个真正的问题,我无法解决。大约30%的时间,当我按F5在Visual Studio上调试我的应用程序时,我在System.Windows.Forms.dll上得到一个AccessVioltaionException。
真正奇怪的是我的应用程序是WPF,我没有任何对Windows Forms的引用,我也没有使用任何可以引用它的库。异常发生在调试会话开始时,我的第一行代码甚至没有在异常之前执行。它只是在我的应用程序调试时发生(如果我在Visual Studio之外启动我的应用程序,它就不会发生)并且它只发生不到一半的时间。有时候,我必须尝试连续调试4到5次才能运行我的应用程序。
我在网上搜索过,找不到任何信息或任何有同样问题的人。我已经有好几个月了。
您认为导致此异常的原因是什么,或者我该如何找到问题的根源?
我在这里发布了Visual Studio上异常的打印屏幕。它是葡萄牙语,但我想你会从图像中理解它。
修改 我将异常详细信息复制到剪贴板,结果文本如下:
System.AccessViolationExceptionnãofoimanipulada 的HResult = -2147467261 消息= Tentativa de ler ou escrevernamemóriaprotegida。 Istoénormalmenteumainindicaçãodeque existeoutramemoóriapanificada。 来源= System.Windows.Forms的 堆栈跟踪: em System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,Int32 msg,IntPtr wParam,IntPtr lParam) em System.Windows.Forms.Control.SendMessage(Int32 msg,Int32 wparam,IntPtr lparam) em System.Windows.Forms.Form.UpdateWindowIcon(Boolean redrawFrame) em System.Windows.Forms.Form.CreateHandle() em System.Windows.Forms.Control.get_Handle() em Microsoft.VisualStudio.HostingProcess.HostProc.RunParkingWindowThread() 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回调,对象状态) em System.Threading.ThreadHelper.ThreadStart() InnerException:
禁用Visual Studio主机进程后,现在在应用程序窗口的Show()方法上抛出AccessViolationException。这是异常的statck跟踪:
*System.AccessViolationException não foi manipulada
HResult=-2147467261
Message=Tentativa de ler ou escrever na memória protegida. Isto é normalmente uma indicação de que existe outra memória danificada.
Source=WindowsBase
StackTrace:
em MS.Win32.UnsafeNativeMethods.CriticalSetWindowTheme(HandleRef hWnd, String subAppName, String subIdList)
em System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
em System.Windows.Window.CreateSourceWindow(Boolean duringShow)
em System.Windows.Window.ShowHelper(Object booleanBox)
em ASilva.Gamer.Dialogs.ProgressWindow.Show(String title, String text) em C:\Users\ASilva\Documents\Visual Studio 2015\Projects\Gamer\Gamer\Dialogs\ProgressWindow.xaml.cs:line 124
em ASilva.Gamer.App.StartupApplication(IEnumerable`1 args) em C:\Users\ASilva\Documents\Visual Studio 2015\Projects\Gamer\Gamer\App.xaml.cs:line 634
em ASilva.Gamer.App.Application_Startup(Object sender, StartupEventArgs e) em C:\Users\ASilva\Documents\Visual Studio 2015\Projects\Gamer\Gamer\App.xaml.cs:line 1263
em System.Windows.Application.OnStartup(StartupEventArgs e)
em ASilva.Gamer.App.OnStartup(StartupEventArgs e) em C:\Users\ASilva\Documents\Visual Studio 2015\Projects\Gamer\Gamer\App.xaml.cs:line 499
em System.Windows.Application.<.ctor>b__1_0(Object unused)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext 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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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.RunDispatcher(Object ignore)
em System.Windows.Application.RunInternal(Window window)
em ASilva.Gamer.App.Main()
InnerException:*
答案 0 :(得分:3)
我没有对Windows窗体的引用
好吧,不是你。但是当你调试你的应用程序然后你真的使用Winforms时,堆栈跟踪不会说谎。它不是您的代码,而是调试器使用的代码创建了该依赖项。容易摆脱,使用项目&gt;属性&gt;调试选项卡&gt;取消选中“启用Visual Studio托管过程”选项。
请记住,这不是Winforms错误。这只是在煤矿中死去的金丝雀。托管进程使用SystemEvents类。为了获取通知并触发其事件,该类需要创建一个窗口。它是隐藏的,只是用于传递通知。
死亡的代码是永远不会死的代码,设置窗口的图标(通常在左上角可见)应该永远不会抛出这样的异常。该程序的名称给出了一些种类,由关心窗户外观的人所拥有。这是由公用事业公司引发的一种崩溃,它改变了窗户铬的外观。
您需要修理机器。它很糟糕。
通过禁用托管流程来解决问题。