Tag: access violation

来自System.Windows.Forms的AccessViolationException,在WPF中使用WinFormsHost

在开发WPF / WinForms互操作应用程序时,我遇到了一个令人讨厌的问题。 我一直试图解决这个问题三天,但我无法取得任何进展。 我怀疑我能提供足够的信息来获得解决方案,但我正在寻找能够解释这里究竟发生了什么的人吗? 我使用的组件是AxMapControl(ESRI ArcGIS Engine 9.3.1 SP2),据我所知,它是COM包装的本机代码,公开为WinForms控件。 该组件使用WPF WinFormsHost代理嵌入在我们的WPF(.NET 3.5)客户端软件中。 应用程序会定期使用AccessViolationException崩溃。 这总是发生在用户鼠标点击地图控件时,但似乎没有任何押韵或原因在什么具体输入。 堆栈跟踪始终相同: System.AccessViolationException:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。 在System.Windows.Forns.Forms.Forf.DefWndProc上的System.Windows.Forms.NativeWindow.DefWndProc(Message&m)处的System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,IntPtr hWnd,Int32 msg,IntPtr wParam,IntPtr lParam) (Message&m)System.Windows.Fornd.OndMessage(Message&m)位于System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)的System.Windows.Forms.AxHost.WndProc(Message&m)处的System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 因为exception似乎抛出了我的代码启动的任何调用堆栈之外,我无法弄清楚如何捕获exception并以编程方式处理它。 此问题发生在调试模式以及发布版本中。 但它确实不会出现在所有计算机上,但我能够在Windows 7和XP以及.NET framework 3.5和4.0上复制此问题。 在崩溃时检查进程是什么,exception似乎是在GAC部署的DLL上似乎有多个CreateFileMapping操作失败,结果FILE LOCKED WITH ONLY READERS 。 此视图已被过滤以仅显示该类型的结果,但似乎每个DLL恰好发生两次。 这是什么意思吗? 现在,很明显我对发生的事情毫无头绪,以及如何解决这个问题。 如果你有一个线索,你能否善待并向我解释我正在处理的问题类型? 知道如何调试这个问题吗?

SqlCeConnection中的访问冲突exception处理

申请/代码说明: 我的应用程序基于c#并使用SQL Server CE,并且我在同一代码位置只获得此exception两次。 在此版本之前没有引入此exception的崩溃。 此版本中唯一的变化是将.net框架更改为4.5.2。 我在处理SqlCeConnection时遇到访问冲突exception,并出现以下错误: 尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。 此exception不会被.net的try catch子句拦截 – 它会导致崩溃。 在我的代码中,我使用以下命令运行 try { var connectionString = string.Format(“{0}{1}{2}”, “Data Source=”, _localDB, “;File Mode=Read Write;Max Database Size=4000;Persist Security Info=False;”); using (var sqlCeConnection = new SqlCeConnection(connectionString)) { using (var sqlCeCommand = new SqlCeCommand()) { sqlCeCommand.Connection = sqlCeConnection; sqlCeCommand.CommandText = “SELECT * FROM Application”; sqlCeConnection.Open(); var […]

访问冲突exceptionc#

这是我的代码抛出一个exception,它只是今天随机开始这里是照片: 这是整个页面代码和错误exception: public frmWFDocumentDetail() { InitializeComponent(); NavigationInTransition navigateInTransition = new NavigationInTransition(); navigateInTransition.Backward = new TurnstileTransition { Mode = TurnstileTransitionMode.BackwardIn }; navigateInTransition.Forward = new TurnstileTransition { Mode = TurnstileTransitionMode.ForwardIn }; NavigationOutTransition navigateOutTransition = new NavigationOutTransition(); navigateOutTransition.Backward = new TurnstileTransition { Mode = TurnstileTransitionMode.BackwardOut }; navigateOutTransition.Forward = new TurnstileTransition { Mode = TurnstileTransitionMode.ForwardOut }; TransitionService.SetNavigationInTransition(this, navigateInTransition); TransitionService.SetNavigationOutTransition(this, […]

AccessViolationException未处理

我正在尝试使用Steve Sanderson的博客文章来编辑ASP MVC 3视图中的可变长度列表。 该项目构建正常,但无论何时呈现局部视图,程序都会在using(Html.BeginColletionItem()行中出现此错误: AccessViolationException was unhandled Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 这是完整例外的屏幕截图 完整的堆栈跟踪如下 at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn) at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at […]

如何测试AccessViolationException的处理

我需要编写一个测试来validation我的代码可以处理AccessViolationException(或任何其他WIN32损坏状态exception – CSE),它通常通过调用第三方库来处理不安全的上下文。 这应该都是使用C#on .net 4.0完成的。 我发现了这个相关的问题如何处理AccessViolationException和这篇相关的文章http://dotnetslackers.com/articles/net/All-about-Corrupted-State-Exceptions-in-NET4.aspx ,它解释了如何捕获这些CSE和他们的背景。 所以我想在测试中激发一个WIN32 CSE,以确保在我的应用程序中正确处理。 就像是: 一些要测试的示例类: public class MyExceptionHandler { [HandleProcessCorruptedStateExceptions] public void HandleCorruptedStateException() { try { //Force genuine unsafe AccessViolationException //not just a throw new AccessViolationException } catch(Exception e) { //Log/cleanup/other } } public void DoesNotHandleCorruptedStateException() { try { //Force genuine unsafe AccessViolationException //not just a throw new […]

为什么*(int *)0 = 0导致访问冲突?

出于教育目的,我正在编写一组方法,这些方法会导致C#中的运行时exception,以了解所有exception是什么以及导致它们的原因。 现在,我正在修补导致AccessViolationException程序。 对我来说最明显的方法是写入受保护的内存位置,如下所示: System.Runtime.InteropServices.Marshal.WriteInt32(IntPtr.Zero, 0); 正如我所希望的那样,这AccessViolationException了一个AccessViolationException 。 我想更简洁地做到这一点,所以我决定编写一个带有不安全代码的程序,并通过为零指针赋值来做(我认为的)完全相同的事情。 unsafe { *(int*)0 = 0; } 由于无法理解的原因,这会抛出NullReferenceException 。 我玩了一些,发现使用*(int*)1而不是抛出NullReferenceException ,但如果使用负数,如*(int*)-1 ,它将抛出一个AccessViolationException 。 这里发生了什么? 为什么*(int*)0 = 0会导致NullReferenceException ,为什么它不会导致AccessViolationException ?

将“Emgu.CV.Mat”分配给`Emgu.CV.UI.ImageBox`(Emgu)时出现’System.AccessViolationException’

您正在尝试将Emgu.CV.Mat分配给Emgu.CV.Mat ,但我在CvInvokeCore.cs文件中遇到System.AccessViolationException错误(第2379行cveMinMaxLoc(iaArr, ref minVal, ref maxVal, ref minLoc, ref maxLoc, iaMask); ): Emgu.CV.World.dll中出现未处理的“System.AccessViolationException”类型exception 附加信息:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。 守则非常简单。 我生成一个位图 Bitmap tmp = mybitmap.getBitmap(); // generates my Bitmap pictureBox1.Image = tmp; // assigning it to an Win Form picture Box works pretty fine imageBox1.Image = ConvertBitmapToMat(tmp); // but converting the Bitmap to an Mat file // and try […]

优雅地处理损坏的状态exception

与此问题相关,我想强制CLR让我的.NET 4.5.2应用程序捕获损坏的状态exception,其唯一目的是记录它们然后终止应用程序。 如果我在应用程序周围的几个地方catch (Exception ex) ,那么这样做的正确方法是什么? 因此,在我指定属性后,如果我理解正确,所有catch (Exception ex)处理程序将捕获像AccessViolationException这样的exception并愉快地继续。 是的,我知道catch (Exception ex)是一个坏主意™,但如果CLR至少将正确的堆栈跟踪放入事件日志中,我将非常乐意向客户解释他的服务器应用程序在凌晨1点快速失败并在夜间离线是一件好事。 但不幸的是,CLR将一个不相关的exception记录到事件日志中,然后关闭该过程,以便我无法找出实际发生的情况。 问题是,如何实现这一目标,流程广泛: if the exception thrown is a Corrupted State Exception: – write the message to the log file – end the process (更新) 换句话说,这可能适用于简单应用程序中的大多数exception: [HandleProcessCorruptedStateExceptions] [SecurityCritical] static void Main() // main entry point { try { } catch (Exception ex) { // […]