-1

Working on a fairly large WPF App with about 40 modules and using Telerik library.

We've been working on that app for a few years and today, for some reason the app started crashing with

"System.AccessViolationException: 'Attempted to read or write protected memory'"

This seems to happen fairly randomly, sometimes copying a grid, opening a context menu or moving a window.

The call stack doesn't say much: (this particular stack trace was when moving a window)

[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)   Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)   Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)   Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)  Unknown
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)  Unknown
PresentationFramework.dll!System.Windows.Application.Run()  Unknown

Avalon.exe!Avalon.App.Main() Line 52 C#

The crashing reason seems very random but always UI interaction related.

It seems something is corrupting the memory, however, there are no unmanaged code.

How to debug such problem, where to start?

Damien
  • 1,492
  • 10
  • 32
  • 1
    Start by checking out previous commits until you find a commit where the application does not crash anymore. If you do not find a non-crashing commit, then the culprit is some nuget package. – Mike Nakis May 23 '23 at 09:45
  • 1
    Have you seen all the answers here? https://stackoverflow.com/q/596413/1136211 – Clemens May 23 '23 at 10:02
  • @MikeNakis this is the first thing I've done, but there does not seem to be anything obvious. No specific threading or unmanaged code. – Damien May 23 '23 at 14:57
  • @Clemens does not seem to be related at all. (no sockets, haven't upgraded anything, that post is winform and this seems to be related to WPF). – Damien May 23 '23 at 14:59

1 Answers1

0

It seems that the issue was caused when copying an object that had bindings to the UI using using Postsharp [NotifyPropertyChanged]

and having the class derived from BindableBase in Prism.MVVM

Damien
  • 1,492
  • 10
  • 32