CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
383 stars 89 forks source link

Access violation reading location exception in XamlHost when closing a WPF .NET Core 3.1 app #211

Closed vladabuba closed 4 years ago

vladabuba commented 4 years ago

Describe the bug

Commercial application I work on uses WPF and .Net Core 3.0 targeting Windows 1903 and up. Application has an XAML Island with UWP's TreeControl inside WPF's Prism module View. It does load an application and it shows up ok. But if I do something in UWP Tree Control in XAML Island, simple thing like dragging item from one location into another, it abruptly ends itself with message:

The program '[30572] myApp.exe' has exited with code -1073741189 (0xc000027b)

Here is the information I got from EventViewer, Control Panel:

Faulting application name: MyApp.exe, version: 5.0.0.23231, time stamp: 0x5d7bb0cb Faulting module name: Windows.UI.Xaml.dll, version: 10.0.18362.449, time stamp: 0x9b7cd6e6 Exception code: 0xc000027b Fault offset: 0x0086b954 Faulting process id: 0x1da8 Faulting application start time: 0x01d5a50a0201cbee Faulting application path: C:\MyApp\netcoreapp3.0\MyApp.exe Faulting module path: C:\Windows\System32\Windows.UI.Xaml.dll Report Id: 7ea2de09-ddff-461e-8861-3c0a7a2954c1 Faulting package full name: Faulting package-relative application ID:

Here is pastebin-ed detailed information from WER file:

https://pastebin.com/ZkvrgjFw

Using latest updates to Visual Studio 2019 Preview to develop application.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to Main Window with UWP Tree Control
  2. Start dragging item in UWP Tree Control
  3. Application abruptly ends

Expected behavior

It should work without crashing or at least to get more detailed information in Output dialog.

Environment

Package Version(s): 

Project .NET Version:
- [ ] .NET Framework (version: )
- [x ] .NET Core 3
- [ ] .NET Core 3.1 Preview (version: )

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x ] May 2019 Update (18362)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x ] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x ] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [ ] 2019 (version: ) 
- [x] 2019 Preview (version: 16.4.0 Preview 6.0)

Additional context

vladabuba commented 4 years ago

Here is the crash when I attach to active process from debugger, click on link Debugger attached

vladabuba commented 4 years ago

More information from Windbg: https://pastebin.com/qYGC10rD

vladabuba commented 4 years ago

Please did you had a chance to look into this issue? This issue blocks using UWP TreeView XAML island inside of our application.

namhnz commented 4 years ago

I also have that issue (with same exit code). The app crashed immediately after appearing icon in taskbar.

ghost commented 4 years ago

This issue has been marked as "needs attention πŸ‘‹" due to no activity for 7 days. Please triage the issue so the fix can be established.

ghost commented 4 years ago

This issue has been marked as "needs attention πŸ‘‹" due to no activity for 7 days. Please triage the issue so the fix can be established.

ghost commented 4 years ago

This issue has been marked as "needs attention πŸ‘‹" due to no activity for 7 days. Please triage the issue so the fix can be established.

mgkcorty commented 4 years ago

Same issue! With identical exit code. I have Wpf Core 3.0 app with UWP UserControl. App crashes instantly or randomly in 2 cases: 1) On startup 2) After scrolling of UWP ListView with 5 UWP InkCanvas as items.

Output: exited with code -1073741189 (0xc000027b) Event Log said about error inside: Windows.UI.Xaml.dll

10.0.18362.449

Note: On clear UWP project (I.e. not Wpf Core 3.0 Xaml Island) identical UserControl code works perfectly.

Note: Same issue after migration from Wpf Core 3.0 to Wpf Core 3.1. After investigation of crash dump I see that error in combase.dll.

Currently development stuck, please investigate and fix issue.

mgkcorty commented 4 years ago

Guys sorry for ping, but you are needed here

@michael-hawker @marb2000 @ocalvo @azchohfi Can I make some fast fix or add crutches for resolve issue? Currently I can’t catch this exception. Application closed instantly. Any ideas friends?

mgkcorty commented 4 years ago

@michael-hawker @marb2000 @ocalvo @azchohfi Still happening. But i detect the correlation, if i have more than 10 items in ListView, frequency of crashes increased on x2.

michael-hawker commented 4 years ago

Thanks @vladabuba and @mgkcortyw for the detailed traces and info on reproducing these issues. I've pinged @marb2000 again as the owner of this area, so hopefully his team can take a look and respond.

marb2000 commented 4 years ago

Ping @Austin-Lamb for awareness

YAJeff commented 4 years ago

I also get this issue when I have a Xaml island hosting a custom control that has a WebView in it's generic template.

marb2000 commented 4 years ago

WebView inside of WindowXamlHost is not a supported scenario.

YAJeff commented 4 years ago

Is there a scenario where embedding the Edge browser, within a WPF .NET Core 3 app, with scriptable runtime objects, does work?

marb2000 commented 4 years ago

No sure about that. You can try the Toolkit Win32 WebView control that our friends from the WebPlatform created which it's not based on DesktopWindowXamlSource (the XAML Islands underneath API).

YAJeff commented 4 years ago

Will give it a shot again, this time with the script notify mechanism. According to this: https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/webview#can-i-inject-native-objects-into-my-webviewcontrol-content ObjectForScripting and WebAllowedObjects isn't supported.

YAJeff commented 4 years ago

For the record, that doesn't work either. It hangs on trying to navigate to any URL. Not sure where to post the issue...

marb2000 commented 4 years ago

So sad seeing this. I hope that the new WebView based on Chromium fix it.

For WinUI 3, we are planning to support the new WebView inside of an Island (no committed yet but we are working on it) but not sure whether it will meet your requirements. Take a look to the current API Spec.

marb2000 commented 4 years ago

About were to report this. You should open a bug (a separated one) in this site so the WebPlatform team triage it. But setting up the exceptions, the huge part of the investments go to the new WebView.

Austin-Lamb commented 4 years ago

@vladabuba - I can try to look at the dump with internal symbols to see if I can figure anything else out. Can you capture a full heap dump of the crash and share it? Or if a full heap dump has too much information, I can try to work with a mini dump, but may be less helpful.

If you don't want to post the dump publicly, let me know and we can work out a way to share the file with just me.

Please @ me in the response, since I'm not regularly checking this repo's issues.

marb2000 commented 4 years ago

@vladabuba Is this still an issue with the updates made for the 6.1.1 version?

mgkcorty commented 4 years ago

@marb2000 Yes, today i make update from 6.0 to 6.1.1 in my project. Issue still happened.

@Austin-Lamb Maybe i can make dump for you? Can i send it to austin.lamb@microsoft.com ?

alexx-grand commented 4 years ago

Hi,

It seems like I have faced the same issue https://www.screencast.com/t/L9lduQ0N6 On WPF Core app shutdown I get the exception: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

Sample app https://1drv.ms/u/s!Am9Q7tHidF2hkT2T6SCojxSgvlE_?e=pO93XY

marb2000 commented 4 years ago

@alexx-grand I couldn't repro this bug using your sample. It compiles and run in the latest version of VS 2019 (also it works with the Preview as well).

image

@mgkcortyw @alexx-grand Do you have other repro?

alexx-grand commented 4 years ago

I use the latest preview of VS 2019
@marb2000 What info can I provide you to help to catch the bug?

marb2000 commented 4 years ago

@alexx-grand I could repro it using another machine with the same config. This is super weird.

"Exception thrown at 0x00007FF98FA01420 (Microsoft.Toolkit.Win32.UI.XamlHost.dll) in WpfApp1.exe: 0xC0000005: Access violation reading location 0x0000000000000000"

I'm going to change the title of the bug based on the error: OLD: WPF .Net Core 3 XAML Island (UWP) application abruptly closes itself NEW: Access violation reading location exception in XamlHost when closing a WPF .NET Core 3.1 app

@ocalvo can you take a look to this?

ocalvo commented 4 years ago

The constructor of the Application object is not calling Initialize(). Please change the constructor to be:

        public App()
        {
            this.Initialize();
            this.InitializeComponent();
        }

After doing this change, the crash no longer happens for me. Please reopen if you are still seeing the issue.