I'm facing a nasty issue when developing a WPF/WinForms interop application. I've been trying to resolve this issue for three days, but I'm unable to make any headway. I doubt I can provide enough information to get a resolution, but I'm looking for anyone who could explain what on earth is going on here?
The component I am using is AxMapControl (ESRI ArcGIS Engine 9.3.1 SP2), which as far as I know is COM-wrapped native code, exposed as a WinForms control. The component is embedded in our WPF (.NET 3.5) client software using WPF WinFormsHost proxy.
Periodically the application crashes hard with an AccessViolationException
. This always happens in reaction to user's mouse click on the map control, but there doesn't seem to be any rhyme or reason on what specific input. Stack trace is always the same:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.AxHost.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Because the exception seems to be thrown outside any call stack initiated by my code, I can't figure out how to catch the exception and handle it programmatically.
This issue happends in debug mode, as well as in release builds. It does however not occur on all computers, but I have been able to replicate this issue on Windows 7 and XP, as well as .NET framework 3.5 and 4.0.
Inspecting what the process is up to at the time of a crash, the anomaly seems to be that there seem to be multiple CreateFileMapping
operations on GAC-deployed DLLs which fail with the result FILE LOCKED WITH ONLY READERS
.
This view has been filtered to show only results of that type, but it seems this happens exactly twice to each DLL. Does this mean something?
Now, it's obvious I am clueless as to what is happening, and how to resolve this issue. If you have a clue, could you be kind and explain to me what type of issue I am dealing with?
Any idea how I could debug this issue?