microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

Enable in-app Toolbar in XAML Hot Reload crashes in App SDK 1.4 #8806

Closed NicholasChrzan closed 8 months ago

NicholasChrzan commented 1 year ago

Describe the bug

When debugging windows app sdk (1.4.230822000) with visual studio 202217.7.3 I get an access violation when opening our application after about 10 seconds, Turning off the "Enable in-app Toolbar" under the XAML hot reload allows the app to start and not crash.

From the crash log: ExceptionAddress: 00007ffd6057de84 (Microsoft_UI_Windowing_Core!Api::ReunionApi32::GetWindowFeatureImpl+0x0000000000000020) ExceptionCode: c0000005 (Access violation) ExceptionFlags: 00000001 NumberParameters: 2 Parameter[0]: 0000000000000000 Parameter[1]: 0000000000000030 Attempt to read from address 0000000000000030

Steps to reproduce the bug

Start app in x64 debug in VS 2022 17.7.3 Open second window Crash

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.4.0: 1.4.230822000

Windows version

Windows 10 (21H2): Build 19044

Additional context

No response

lhak commented 1 year ago

I see the same issue. Here is a stack trace:

Microsoft.UI.Windowing.Core.dll!Api::ReunionApi32::GetWindowFeatureImpl(enum Core::WindowHandle,unsigned int)
 Microsoft.UI.Windowing.Core.dll!GetWindowFeature()
 Microsoft.UI.Input.dll!InputNonClientPointerSourceWinRTStatics::GetForWindowIdHelper(struct Microsoft::UI::WindowId,struct Microsoft::UI::Input::IInputNonClientPointerSource * *,bool)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!winrt::impl::factory_cache_entry<struct winrt::Microsoft::UI::Input::InputNonClientPointerSource,struct winrt::Microsoft::UI::Input::IInputNonClientPointerSourceStatics>::call<class `winrt::Microsoft::UI::Input::InputNonClientPointerSource::GetForWindowId(struct winrt::Microsoft::UI::WindowId const &)'::`2'::<lambda_1> &>(class `winrt::Microsoft::UI::Input::InputNonClientPointerSource::GetForWindowId(struct winrt::Microsoft::UI::WindowId const &)'::`2'::<lambda_1> &)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!winrt::Microsoft::UI::Input::InputNonClientPointerSource::GetForWindowId(struct winrt::Microsoft::UI::WindowId const &)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::InAppMenu::InAppMenu(class Microsoft::VisualStudio::DesignTools::UwpTap::ActivationFactoryProviderBase &,class std::shared_ptr<class Microsoft::VisualStudio::DesignTools::UwpTap::OM::ObjectIdentityService>,struct Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::InAppMenuModel &,struct winrt::Microsoft::UI::Xaml::Controls::Panel,struct winrt::Microsoft::UI::Xaml::XamlRoot,struct HWND__ *)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::UILayerManager::OnInAppMenuStateChanged(void)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::WinrtRunOnUIThread<class std::function<void > >(class Microsoft::VisualStudio::DesignTools::UwpTap::DispatcherHelper const &,enum Microsoft::VisualStudio::DesignTools::UwpTap::DispatcherPriority,class std::function<void >)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!std::_Func_impl_no_alloc<class `Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::DispatcherBindingBase<bool>::Initialize(class std::function<void >,bool)'::`5'::<lambda_1>,void>::_Do_call(void)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::SimpleBinding<bool>::Initialize(class std::function<void >,bool)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::DispatcherBindingBase<bool>::Initialize(class std::function<void >,bool)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::UILayerManager::SetBinding(class Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::NotifyingValue<bool> &,void )
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::UILayerManager::Initialize(void)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::UILayerManager::RunOnUIThread(class std::function<void > const &)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::InAppUI::UILayerManager::Initialize(struct winrt::Microsoft::UI::Xaml::Controls::Panel,struct HWND__ *)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!std::_Func_impl_no_alloc<`Microsoft::VisualStudio::DesignTools::UwpTap::WindowsXamlDiagnosticsTap::AddRoot'::`2'::<lambda_1>,void>::_Do_call()
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!Microsoft::VisualStudio::DesignTools::UwpTap::PackagedTask<void>::operator()(void)
 Microsoft.VisualStudio.DesignTools.WinUITap.dll!winrt::impl::delegate<winrt::Microsoft::UI::Dispatching::DispatcherQueueHandler,`Microsoft::VisualStudio::DesignTools::UwpTap::WinrtRunOnUIThreadAsync<`Microsoft::VisualStudio::DesignTools::UwpTap::WindowsXamlDiagnosticsTap::AddRoot'::`2'::<lambda_1>>'::`2'::<lambda_1>>::Invoke()
 CoreMessagingXP.dll!Microsoft::UI::Dispatching::DispatcherQueue::DeferInvokeCallback(void *)
 CoreMessagingXP.dll!CFlat::SehSafe::Execute<<lambda_a81ff790741c2a62f2197c2561f5fe49>>()
 CoreMessagingXP.dll!Microsoft::CoreUI::ActionCallback::ImportAdapter$(class CFlat::Box$1<struct CFlat::FunctionPointerAndUserData$1<long > > *)
 CoreMessagingXP.dll!Microsoft::CoreUI::Messaging::MessageSession::Callback_InvokeDeferInvoke(class Microsoft::CoreUI::ActionCallback *,struct System::UIntPtr)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::DeferredCall::Callback_Dispatch(void)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::DeferredCallDispatcher::Callback_OnDispatch(void)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchNextItem(class Microsoft::CoreUI::Dispatch::DispatchItem *)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchLoop(enum Microsoft::CoreUI::Dispatch::RunnablePriorityMask)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop(enum Microsoft::CoreUI::Dispatch::RunMode)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::DrainCoreMessagingQueue(enum Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority,void * *)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch(bool,enum Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority,void * *)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatchRaw(enum Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority,bool,void * *)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::DoWork(struct HWND__ *,enum Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority,bool)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::HandleDispatchNotifyMessage(struct HWND__ *,unsigned __int64,__int64)
 CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::UserAdapter::WindowProc(struct HWND__ *,unsigned int,unsigned __int64,__int64)
NicholasChrzan commented 1 year ago

Turning off the "Enable in-app Toolbar" fixes this issue for me, so you can still use XAML Hot Reload

Zulu-Inuoe commented 1 year ago

Seeing the same behaviour - Disabling the 'Enable in-app Toolbar' avoids the crash

castorix commented 1 year ago

Turning off the "Enable in-app Toolbar" fixes this issue for me, so you can still use XAML Hot Reload

Thanks, it also fixes the issue for XAML Islands in WPF which crashed with "access violation", while the same code worked in WinForms

Zulu-Inuoe commented 1 year ago

@JoeTomkinson this is not closed - the duplicate #8848 was

JoeTomkinson commented 1 year ago

@JoeTomkinson this is not closed - the duplicate #8848 was

Apologies, was viewing this on mobile to check the status and clearly misread.

JochemPalmsens commented 11 months ago

Same issue here... and now my front-end developers aren't happy with us upgrading to 1.4. So it's pretty blocking for us!

Scottj1s commented 11 months ago

internal MS issue: https://task.ms/47919577

Zulu-Inuoe commented 9 months ago

@JoeTomkinson so I guess this is actually closed now.

JochemPalmsens commented 9 months ago

@llongley what's the dupe? We're still waiting on this and it's blocking us moving to 1.4

Scottj1s commented 9 months ago

This issue was addressed in Visual Studio version 17.8

JochemPalmsens commented 9 months ago

@Scottj1s thank you for your answer, but could you clarify that? Because I just tried it and still get the issue.

I'm running visual studio 17.8.6.

that's the same behavior as before, so I don't see how it's "completed"?

Like said: our front-end developers are using that toolbar, so they don't want us to switch to 1.4 this way. It's still blocking us.

Screenshot: afbeelding

irperez commented 9 months ago

@Scottj1s thank you for your answer, but could you clarify that? Because I just tried it and still get the issue.

I'm running visual studio 17.8.6.

  • When I run the (multi window) app using WinApp SDK 1.3.230724000 the (XAML hot-reload) in-app toolbar runs fine
  • When I run WinApp SDK 1.4.231219000 with in-app toolbar enabled, the app (still) crashes.
  • When I disable the in-app toolbar, the app starts without exceptions again.

that's the same behavior as before, so I don't see how it's "completed"?

Like said: our front-end developers are using that toolbar, so they don't want us to switch to 1.4 this way. It's still blocking us.

Screenshot: afbeelding

I just wanted to confirm that at my company we are seeing the same issue.

We're running visual studio 17.8.5.
Windows v10.0.19045 Build 19045

We have over 50 developers with the same issue here.

NicholasChrzan commented 9 months ago

@irperez @JochemPalmsens While the in app toolbar does still have this issue. We've been able to work around this using the "Live Visual Tree" window in visual studio. The toolbar there has many of the same functions (if not all) as the in app toolbar and still works without issue.

@Scottj1s @llongley This issue still exists in VS 2022 17.8.6 and has not been addressed. One of these issues should be re-opened.

JochemPalmsens commented 9 months ago

I just tried it with the new Visual Studio 2022 releases today:

So apparently it was addressed in 17.9, not 17.8... but it's not fixed

Details: It's more that it sometimes seems to work in 17.9, but sometimes also doesn't. I had to do a very thorough clean (delete obj/bin directories manually) and multiple rebuilds before I could run the app without crashing using 1.4 or even 1.5. But after a new checkout it crashes again. The only thing always starting is WinAppSDK 1.3

Update 19-2-2024: we made all colleagues update to Visual Studio 17.9 and rolled out a test update to WinAppSDK 1.4. Even after thorough cleaning of build directories, almost everybody had problems with the in-app toolbar, so we need to stay at WinApp SDK 1.3 until this is really fixed.

@Scottj1s So it seems there still are issues.

Scottj1s commented 8 months ago

@irperez , @JochemPalmsens , @NicholasChrzan - thanks all for your feedback. We're engaging with the Visual Studio team to root cause. I was unable to repro this myself, after updating to VS 17.8+. But evidently, you all are still seeing the crash on latest VS.

Scottj1s commented 8 months ago

This crash was manifesting from two location:

I don't understand why the crash still repros with VS 17.8+. The Visual Studio team has requested a VS feedback item, ideally with a repro project, and at minimum a crash dump.

In addition, the hardening in Windows App SDK 1.5 should also resolve this crash, so upgrading is another option.

irperez commented 8 months ago

Just to confirm what we're seeing, below are the versions we're using. I didn't provide enough detail.

Related Versions

Visual Studio Professional 17.8.5. Windows v10.0.19045 Build 19045 Microsoft.WindowsAppSDK 1.4.231008000 Microsoft.Windows.SDK.BuildTools 10.0.22621.756

From the About Dialog:

Microsoft Visual Studio Professional 2022 Version 17.8.5 VisualStudio.17.Release/17.8.5+34511.84 Microsoft .NET Framework Version 4.8.04084

Installed Version: Professional

Visual C++ 2022 00476-80000-00000-AA140 Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.8.358.6298 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.8.358.6298 Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.8.358.6298 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Copy Nice 1.0.7 Strips leading indentation when copying to the clipboard. This fixes the issue of tangled code when pasting code into an email, IM, or elsewhere.

CreateUnitTestBoilerplateCommand Extension 1.0 CreateUnitTestBoilerplateCommand Visual Studio Extension Detailed Info

File Differ 3.0.49 The easiest way to diff two files directly in Solution Explorer

File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer

Fine Code Coverage FineCodeCoverage2022.ad53fb28-7a11-4465-a27a-3550499ea4a1 Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)

GitHub Copilot 1.137.0.0 (v1.137.0.0@2f127d06d) GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

GitHub Copilot Agent 1.137.0

ILSpy.AddIn 1.0 Integration of the ILSpy Decompiler into Visual Studio.

Insert Guid 1.3.6 Makes it super easy to insert a new GUID into any editor and input field

Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.8.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio 17.6.34024.01 Microsoft Office Developer Tools for Visual Studio

Rainbow Braces 1.0.155 Colorizes matching brace pairs to make it easy to identify them and their scope. Works for curly brackets, parentheses, and square brackets.

Razor (ASP.NET Core) 17.8.3.2405201+d135dd8d2ec1c2fbdee220e8656b308694e17a4b Provides languages services for ASP.NET Core Razor.

Snippet Designer 1.8.1 Snippet Designer is a Visual Studio plug in which allows you to create and search for snippets inside the IDE

SQL Server Data Tools 17.8.120.1 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 17.0.20920.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager.

Prochy commented 8 months ago

@Scottj1s I'm able to reproduce it if I checkout H.NotifyIcon git repo and run it. With "Enable in-app toolbar" ON it crashes, if it's OFF it works fine. I hope it will help somehow. :) I uploaded simplified NotifyIcon project where I removed unnecessary projects. Not sure why, but H.NotifyIcon.Apps.WinUI is not working with the "Enable in-app toolbar" and H.NotifyIcon.Apps.WinUI.Windowless is working fine. Didn't investigate deeper.

VS 17.9.0 WinAppSdk 1.5 Preview 1 reproducibleExample.zip

Scottj1s commented 8 months ago

Sorry for the confusion, and thanks for the repro @Prochy - very helpful. I've confirmed that the fix is in the WinAppSDK 1.5 release candidate (and not in Preview 1). image

JochemPalmsens commented 8 months ago

Well that's good news... although we have no way to test if it works for our projects yet. I guess we'll have to wait. When is the RC released?

In the meantime I made a minimal test solution (to compare 1.3, 1.4 and 1.5): https://github.com/JochemPalmsens/WinAppSDKbug8806

Just adding a second window on launched triggers the bug.

JochemPalmsens commented 8 months ago

I can confirm that (at least it seems so) it's fixed in 1.5.240227000 image

wbokkers commented 2 months ago

I see this crash happening all the time in App SDK 1.6 when closing (child)Windows. Hot Reload is broken for me.