`System.AccessViolationException` in `ListViewGroup_Footer_GetGroupInfo_Success` tests
See original GitHub issueProblem description:
https://github.com/dotnet/winforms/pull/2654 introduced tests for ListViewGroup.Footer that are failing on CI agents with the following stack:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ListView.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW[[Interop+ComCtl32+LVGROUPW, System.Windows.Forms.Primitives, Version=42.42.42.42, Culture=neutral, PublicKeyToken=b77a5c561934e089]](IntPtr, WM, IntPtr, LVGROUPW ByRef)
at System.Windows.Forms.Tests.ListViewTests+<>c.<ListView_Handle_GetWithGroups_Success>b__62_0()
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
at Microsoft.DotNet.RemoteExecutor.Program.Main(System.String[])
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ListView.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW[[Interop+ComCtl32+LVGROUPW, System.Windows.Forms.Primitives, Version=42.42.42.42, Culture=neutral, PublicKeyToken=b77a5c561934e089]](IntPtr, WM, IntPtr, LVGROUPW ByRef)
at System.Windows.Forms.Tests.ListViewGroupTests+<>c.<ListViewGroup_Footer_GetGroupInfo_Success>b__10_0()
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
at Microsoft.DotNet.RemoteExecutor.Program.Main(System.String[])
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ListView.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW[[Interop+ComCtl32+LVGROUPW, System.Windows.Forms.Primitives, Version=42.42.42.42, Culture=neutral, PublicKeyToken=b77a5c561934e089]](IntPtr, WM, IntPtr, LVGROUPW ByRef)
at System.Windows.Forms.Tests.ListViewGroupTests+<>c.<ListView_FooterAlignment_GetGroupInfo_Success>b__16_0(System.String, System.String, System.String)
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
at Microsoft.DotNet.RemoteExecutor.Program.Main(System.String[])
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ListView.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW[[Interop+ComCtl32+LVGROUPW, System.Windows.Forms.Primitives, Version=42.42.42.42, Culture=neutral, PublicKeyToken=b77a5c561934e089]](IntPtr, WM, IntPtr, LVGROUPW ByRef)
at System.Windows.Forms.Tests.ListViewGroupTests+<>c.<ListView_FooterAlignment_GetGroupInfo_Success>b__16_0(System.String, System.String, System.String)
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
at Microsoft.DotNet.RemoteExecutor.Program.Main(System.String[])
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.CallWindowProcW(IntPtr, IntPtr, WM, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ListView.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW(IntPtr, WM, IntPtr, IntPtr)
at Interop+User32.SendMessageW[[Interop+ComCtl32+LVGROUPW, System.Windows.Forms.Primitives, Version=42.42.42.42, Culture=neutral, PublicKeyToken=b77a5c561934e089]](IntPtr, WM, IntPtr, LVGROUPW ByRef)
at System.Windows.Forms.Tests.ListViewGroupTests+<>c.<ListView_FooterAlignment_GetGroupInfo_Success>b__16_0(System.String, System.String, System.String)
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
at Microsoft.DotNet.RemoteExecutor.Program.Main(System.String[])
Expected behavior:
- Failing tests are reported and builds are marked as failed
ListView_FooterAlignment_GetGroupInfo_Successtests pass
/cc: @hughbe
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
NUnit test fails because of System.AccessViolationException
AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. This error ...
Read more >AccessViolationException Class (System)
An AccessViolationException exception is always thrown by an attempt to access protected memory -- that is, to access memory that is not allocated...
Read more >Fatal error. System.AccessViolationException · Issue #2503
Reason: Test host process crashed : Fatal error. System.AccessViolationException: Attempted to read or write protected memory.
Read more >AccessViolationException is thrown while debugging the test
When I tried to debug the unit test code, I am getting below exception: An exception of type 'System.AccessViolationException' occurred in ...
Read more >Attempted to read or write protected memory. This is often an ...
When running code coverage, a test will randomly fail (not the same one) with the following issue. System.AccessViolationException: Attempted to read or write ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yep, I’m slowly getting there… First we need https://github.com/dotnet/winforms/pull/2988 as a base, so we know when remotely executed tests fail. I’ll pick up this tomorrow
Given that it fails in the RemoteExecutor process I wonder if its possible to take the test code and repro (and debug) in a standalone application?
It seems RemoteExecutor isn’t STA and the test isn’t setting up a proper application message loop either, so maybe we are seeing a loophole where WinForms (or rather one of its referenced native components) doesn’t get properly initialized.[edit] yes putting it in a standalone program repros the crash and allows debugging - no the problem is not related to STA or other process initialization, still crashes when putting the code into an otherwise normal WinForms sample application. x86 vs x64 makes no difference, so no sign extension error either.