dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
572 stars 36 forks source link

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' #158

Closed dfmacom closed 5 months ago

dfmacom commented 5 months ago

With a new blank app project template created, changing the base class of MainWindow.cs to WindowEx as shown in the WinUI concept github page results in an unhandled memory exception in the MainWindow constructor.

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

image

Steps to reproduce:

  1. Create new WinUI3 project with the blank project template.
  2. Change MainWindow.cs and MainWindow.xaml.cs as shown in the steps in the link above.
  3. Build and run

Note that this issue seems to remain even after changing the base class back to "Window". The project can still build but the unhandled exception pictured continues to occur. It seems that it corrupted the project or something.

dfmacom commented 5 months ago

Uhm so I actually repeated this process again and it didn't happen this time. I will leave it up just so it is seen as it did happen as described and that project still seems corrupted. Handle this issue as you see fit

dotMorten commented 5 months ago

Did you change the type both in xaml and code behind ?

dfmacom commented 5 months ago

Did you change the type both in xaml and code behind ?

Yes

dotMorten commented 5 months ago

So you don’t have a consistent repro any longer or does the original project still exhibit this behavior? TBH sounds like the typical weird WinUI random instability and not a WinUIEx specific issue.

dfmacom commented 5 months ago

I do have the original project and it is still exhibiting the behavior that throws the exception. I can upload it as a public repo and link you to it in a bit, I need to clean some proprietary stuff out of it.

I would not be surprised if it is what you described as some of the WinUI random instability, though. There seems to still be plenty of that. Hopefully it will continue to be improved by the WinUI team

dotMorten commented 5 months ago

Close VS and delete bin and obj folders. Then open it again and see if it repros. My guess is some cache value from before you changing it wreaking havoc

dfmacom commented 5 months ago

I did that a few times among other things before opening the issue.

Also, are the WinUIEX.TestTools and WinUIEX.TestTools.MsTest packages supported in .NET8?

TomPMoleman commented 5 months ago

Faced the same issue, but I rather linked it to the Windows App SDK version 1.4.x (since the access violation exception was thrown even without using any WinUiEx functionality at all ... merely creating 2 instances of a window was sufficient to trigger the error).

Please have a look at the corresponding issue I just created: https://github.com/microsoft/microsoft-ui-xaml/issues/9310

dotMorten commented 5 months ago

@dfmacom I'm no longer maintaining the test tools and will be removed at some point, but there's nothing in there that prevents it from being used by a newer targetframework.

dotMorten commented 5 months ago

@TomPMoleman Thank you. Closing this issue since it's external.