Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView2 crash on startup #3117

Closed
danielchau opened this issue Nov 7, 2022 · 10 comments
Closed

WebView2 crash on startup #3117

danielchau opened this issue Nov 7, 2022 · 10 comments
Assignees
Labels
area-WebView bug Something isn't working

Comments

@danielchau
Copy link

Describe the bug

After following the guide here to set up WebView2 with WinAppSDK here and upgrading the WinAppSDK version to 1.2.220930.4-preview2, the WebView2 crashes on startup.

Output Error:
Exception thrown at 0x00007FFC8506407A (imm32.dll) in WebView2Simple.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Callstack traces back to EmbeddedBrowserWebView.dll Initialize()

This error does not occur in the latest stable version 1.1.5.

Steps to reproduce the bug

  1. Go to https://github.com/danielchau/winappsdk-webview2 or go to https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/winui and follow the guide with WinAppSDK version 1.2.220930.4-preview2.
  2. Start app
  3. Notice "Access violation reading location"

Expected behavior

For WebView2 to startup and show webpage.

Screenshots

No response

NuGet package version

1.2.220930.4-preview2

Packaging type

No response

Windows version

Insider Build (xxxxx)

IDE

Visual Studio 2022

Additional context

No response

@lyahdav
Copy link

lyahdav commented Nov 7, 2022

For searchability, here's the full call stack for me:

 	imm32.dll!CtfImmGetTMAEFlags()	Unknown
 	msctf.dll!CThreadInputMgr::CreateInstance()	Unknown
 	combase.dll!CServerContextActivator::CreateInstance(IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties) Line 881	C++
 	combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter, IActivationPropertiesOut * * ppActPropsOut) Line 1983	C++
 	combase.dll!CApartmentActivator::CreateInstance(IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties) Line 2189	C++
 	combase.dll!CProcessActivator::CCICallback(unsigned long dwContext, IUnknown * pUnkOuter, ActivationPropertiesIn * pActIn, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties) Line 1640	C++
 	combase.dll!CProcessActivator::AttemptActivation(ActivationPropertiesIn * pActIn, IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties, HRESULT(CProcessActivator::*)(unsigned long, IUnknown *, ActivationPropertiesIn *, IActivationPropertiesIn *, IActivationPropertiesOut * *) pfnCtxActCallback, unsigned long dwContext) Line 1527	C++
 	combase.dll!CProcessActivator::ActivateByContext(ActivationPropertiesIn * pActIn, IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties, HRESULT(CProcessActivator::*)(unsigned long, IUnknown *, ActivationPropertiesIn *, IActivationPropertiesIn *, IActivationPropertiesOut * *) pfnCtxActCallback) Line 1371	C++
 	combase.dll!CProcessActivator::CreateInstance(IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties) Line 1271	C++
 	combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter, IActivationPropertiesOut * * ppActPropsOut) Line 1983	C++
 	combase.dll!CClientContextActivator::CreateInstance(IUnknown * pUnkOuter, IActivationPropertiesIn * pInActProperties, IActivationPropertiesOut * * ppOutActProperties) Line 570	C++
 	combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter, IActivationPropertiesOut * * ppActPropsOut) Line 1983	C++
 	combase.dll!ICoCreateInstanceEx(const _GUID & OriginalClsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, unsigned long dwActvFlags, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 2032	C++
 	combase.dll!CComActivator::DoCreateInstance(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 392	C++
 	[Inline Frame] combase.dll!CoCreateInstanceEx(const _GUID &) Line 177	C++
 	combase.dll!CoCreateInstance(const _GUID & rclsid, IUnknown * pUnkOuter, unsigned long dwContext, const _GUID & riid, void * * ppv) Line 121	C++
 	EmbeddedBrowserWebView.dll!ui::TSFBridge::Initialize(bool)	Unknown
 	EmbeddedBrowserWebView.dll!embedded_browser_webview_current::Controller::Initialize(struct HWND__ *,struct IUnknown *,class embedded_browser::mojom::EmbeddedBrowser *)	Unknown
 	EmbeddedBrowserWebView.dll!embedded_browser_webview_current::EmbeddedBrowserWebView::RuntimeClassInitialize(class std::Cr::unique_ptr<struct embedded_browser_webview_current::WebViewCreationParams,struct std::Cr::default_delete<struct embedded_browser_webview_current::WebViewCreationParams> >,class base::OnceCallback<void > &&)	Unknown
 	EmbeddedBrowserWebView.dll!embedded_browser_webview_current::internal::EBWebViewEnvironment::CreateWebViewGeneric()	Unknown
 	EmbeddedBrowserWebView.dll!embedded_browser_webview_current::internal::EBWebViewEnvironment::CreateCoreWebView2CompositionControllerWithOptions(struct HWND__ *,struct ICoreWebView2ControllerOptions *,struct ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler *)	Unknown
 	Microsoft.Web.WebView2.Core.dll!winrt::Microsoft::Web::WebView2::Core::implementation::CoreWebView2Environment::CreateCoreWebView2CompositionControllerAsync$_ResumeCoro$1()	Unknown
 	Microsoft.Web.WebView2.Core.dll!winrt::Microsoft::Web::WebView2::Core::implementation::CoreWebView2Environment::CreateCoreWebView2CompositionControllerAsync$_InitCoro$2()	Unknown
 	Microsoft.Web.WebView2.Core.dll!winrt::Microsoft::Web::WebView2::Core::implementation::CoreWebView2Environment::CreateCoreWebView2CompositionControllerAsync(struct winrt::Microsoft::Web::WebView2::Core::CoreWebView2ControllerWindowReference)	Unknown
 	Microsoft.Web.WebView2.Core.dll!winrt::impl::produce<struct winrt::Microsoft::Web::WebView2::Core::implementation::CoreWebView2Environment,struct winrt::Microsoft::Web::WebView2::Core::ICoreWebView2Environment3>::CreateCoreWebView2CompositionControllerAsync(void *,void * *)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::consume_Microsoft_Web_WebView2_Core_ICoreWebView2Environment3<struct winrt::Microsoft::Web::WebView2::Core::CoreWebView2Environment>::CreateCoreWebView2CompositionControllerAsync(struct winrt::Microsoft::Web::WebView2::Core::CoreWebView2ControllerWindowReference const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreWebViewFromEnvironment$_ResumeCoro$1()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreWebViewFromEnvironment$_InitCoro$2()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreWebViewFromEnvironment(struct HWND__ *)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreObjects$_ResumeCoro$1()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::resume_apartment()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::delegate<struct winrt::Windows::Foundation::AsyncOperationCompletedHandler<struct winrt::Microsoft::Web::WebView2::Core::CoreWebView2CompositionController>,class `winrt::impl::await_adapter<struct winrt::Windows::Foundation::IAsyncOperation<struct winrt::Microsoft::Web::WebView2::Core::CoreWebView2CompositionController> >::await_suspend(struct std::experimental::coroutine_handle<void>)'::`2'::<lambda_1> >::Invoke(void *,int)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::Windows::Foundation::AsyncOperationCompletedHandler<struct winrt::hstring>::operator()(struct winrt::Windows::Foundation::IAsyncOperation<struct winrt::hstring> const &,enum winrt::Windows::Foundation::AsyncStatus const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::invoke<struct winrt::Windows::Foundation::AsyncActionCompletedHandler,struct winrt::impl::promise_base<struct std::experimental::coroutine_traits<struct winrt::Windows::Foundation::IAsyncAction,class WebView2 *>::promise_type,struct winrt::Windows::Foundation::IAsyncAction,void>,enum winrt::Windows::Foundation::AsyncStatus>(struct winrt::Windows::Foundation::AsyncActionCompletedHandler const &,struct winrt::impl::promise_base<struct std::experimental::coroutine_traits<struct winrt::Windows::Foundation::IAsyncAction,class WebView2 *>::promise_type,struct winrt::Windows::Foundation::IAsyncAction,void> const &,enum winrt::Windows::Foundation::AsyncStatus const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::promise_base<struct std::experimental::coroutine_traits<struct winrt::Windows::Foundation::IAsyncAction,class WebView2 *>::promise_type,struct winrt::Windows::Foundation::IAsyncAction,void>::Completed(struct winrt::Windows::Foundation::AsyncActionCompletedHandler const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::produce<struct std::experimental::coroutine_traits<struct winrt::Windows::Foundation::IAsyncAction,class WebView2 *>::promise_type,struct winrt::Windows::Foundation::IAsyncAction>::put_Completed(void *)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::consume_Windows_Foundation_IAsyncAction<struct winrt::Windows::Foundation::IAsyncAction>::Completed(struct winrt::Windows::Foundation::AsyncActionCompletedHandler const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::await_adapter<struct winrt::Windows::Foundation::IAsyncAction>::await_suspend(struct std::experimental::coroutine_handle<void>)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreObjects$_ResumeCoro$1()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreObjects$_InitCoro$2()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::CreateCoreObjects(void)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::OnSourceChanged$_ResumeCoro$1()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::OnSourceChanged$_InitCoro$2()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::OnSourceChanged(struct winrt::Windows::Foundation::Uri)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2::OnPropertyChanged(struct winrt::Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2Properties::OnCanGoBackPropertyChanged(struct winrt::Microsoft::UI::Xaml::DependencyObject const &,struct winrt::Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::delegate<struct winrt::Microsoft::UI::Xaml::PropertyChangedCallback,class `winrt::Microsoft::UI::Xaml::PropertyChangedCallback::Xaml<void >(void (*)(struct winrt::Microsoft::UI::Xaml::DependencyObject const &,struct winrt::Microsoft::UI::Xaml::DependencyPropertyChangedEventArgs const &))'::`1'::<lambda_363_> >::Invoke(void *,void *)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::NotifyPropertyChanged()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::SetEffectiveValue()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::UpdateEffectiveValue()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CFrameworkElement::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CPanel::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValueCore()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::UpdateEffectiveValue()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValueInternal()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValue()	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::consume_Microsoft_UI_Xaml_IDependencyObject<class RadioMenuFlyoutItem>::SetValue(struct winrt::Microsoft::UI::Xaml::DependencyProperty const &,struct winrt::Windows::Foundation::IInspectable const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!WebView2Properties::Source(struct winrt::Windows::Foundation::Uri const &)	Unknown
 	Microsoft.UI.Xaml.Controls.dll!winrt::impl::produce<class WebView2,struct winrt::Microsoft::UI::Xaml::Controls::IWebView2>::put_Source(void *)	Unknown
>	MyWebView2WinUI3.exe!winrt::impl::consume_Microsoft_UI_Xaml_Controls_IWebView2<winrt::Microsoft::UI::Xaml::Controls::IWebView2>::Source(const winrt::Windows::Foundation::Uri & value) Line 23422	C++
 	MyWebView2WinUI3.exe!winrt::MyWebView2WinUI3::implementation::SetReferenceTypeMember_Source<winrt::Microsoft::UI::Xaml::Controls::WebView2,winrt::Windows::Foundation::Uri>(const winrt::Windows::Foundation::IInspectable & instance, const winrt::Windows::Foundation::IInspectable & value) Line 150	C++
 	MyWebView2WinUI3.exe!winrt::MyWebView2WinUI3::implementation::XamlMember::SetValue(const winrt::Windows::Foundation::IInspectable & instance, const winrt::Windows::Foundation::IInspectable & value) Line 634	C++
 	MyWebView2WinUI3.exe!winrt::impl::produce<winrt::MyWebView2WinUI3::implementation::XamlMember,winrt::Microsoft::UI::Xaml::Markup::IXamlMember>::SetValue(void * instance, void * value) Line 839	C++
 	Microsoft.ui.xaml.dll!DirectUI::XamlParserCallbacks::XamlManagedRuntimeRPInvokes_SetValue()	Unknown
 	Microsoft.ui.xaml.dll!XamlManagedRuntime::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!ObjectWriterRuntime::SetValueImpl()	Unknown
 	Microsoft.ui.xaml.dll!BinaryFormatObjectWriter::SetValueOnCurrentInstance()	Unknown
 	Microsoft.ui.xaml.dll!BinaryFormatObjectWriter::WriteNode()	Unknown
 	Microsoft.ui.xaml.dll!CParser::LoadXamlCore()	Unknown
 	Microsoft.ui.xaml.dll!CCoreServices::ParseXamlWithExistingFrameworkRoot()	Unknown
 	Microsoft.ui.xaml.dll!CApplication::LoadComponent()	Unknown
 	Microsoft.ui.xaml.dll!CoreImports::Application_LoadComponent()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::LoadComponent()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationFactory::LoadComponentWithResourceLocationImpl()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationFactory::LoadComponentWithResourceLocation()	Unknown
 	MyWebView2WinUI3.exe!winrt::impl::consume_Microsoft_UI_Xaml_IApplicationStatics<winrt::Microsoft::UI::Xaml::IApplicationStatics>::LoadComponent(const winrt::Windows::Foundation::IInspectable & component, const winrt::Windows::Foundation::Uri & resourceLocator, const winrt::Microsoft::UI::Xaml::Controls::Primitives::ComponentResourceLocation & componentResourceLocation) Line 165	C++
 	MyWebView2WinUI3.exe!winrt::Microsoft::UI::Xaml::Application::LoadComponent::__l2::<lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics & f) Line 12154	C++
 	MyWebView2WinUI3.exe!winrt::impl::call_factory<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics,void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &)>(winrt::Microsoft::UI::Xaml::Application::LoadComponent::__l2::void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) && callback) Line 6304	C++
 	MyWebView2WinUI3.exe!winrt::Microsoft::UI::Xaml::Application::LoadComponent(const winrt::Windows::Foundation::IInspectable & component, const winrt::Windows::Foundation::Uri & resourceLocator, const winrt::Microsoft::UI::Xaml::Controls::Primitives::ComponentResourceLocation & componentResourceLocation) Line 12155	C++
 	MyWebView2WinUI3.exe!winrt::MyWebView2WinUI3::implementation::MainWindowT<winrt::MyWebView2WinUI3::implementation::MainWindow>::InitializeComponent() Line 31	C++
 	MyWebView2WinUI3.exe!winrt::MyWebView2WinUI3::implementation::MainWindow::MainWindow() Line 17	C++
 	MyWebView2WinUI3.exe!winrt::impl::heap_implements<winrt::MyWebView2WinUI3::implementation::MainWindow>::heap_implements<winrt::MyWebView2WinUI3::implementation::MainWindow>()	C++
 	MyWebView2WinUI3.exe!winrt::make<winrt::MyWebView2WinUI3::implementation::MainWindow>() Line 7761	C++
 	MyWebView2WinUI3.exe!winrt::MyWebView2WinUI3::implementation::App::OnLaunched(const winrt::Microsoft::UI::Xaml::LaunchActivatedEventArgs & __formal) Line 44	C++
 	MyWebView2WinUI3.exe!winrt::impl::produce<winrt::MyWebView2WinUI3::implementation::App,winrt::Microsoft::UI::Xaml::IApplicationOverrides>::OnLaunched(void * args) Line 5034	C++
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationGenerated::OnLaunchedProtected()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::InvokeOnLaunchActivated()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::StartOnCurrentThreadImpl()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationGenerated::StartOnCurrentThread()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::WindowsXamlManager::XamlCore::Initialize()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::WindowsXamlManager::Initialize()	Unknown
 	Microsoft.ui.xaml.dll!ctl::ComObjectBase::CreateInstanceBase()	Unknown
 	Microsoft.ui.xaml.dll!ctl::ComObject<DirectUI::WindowsXamlManager>::CreateInstance<DirectUI::WindowsXamlManager>()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThreadImpl()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThread()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::StartDesktop()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationFactory::Start()	Unknown
 	MyWebView2WinUI3.exe!winrt::impl::consume_Microsoft_UI_Xaml_IApplicationStatics<winrt::Microsoft::UI::Xaml::IApplicationStatics>::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 157	C++
 	MyWebView2WinUI3.exe!winrt::Microsoft::UI::Xaml::Application::Start::__l2::<lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics & f) Line 12146	C++
 	MyWebView2WinUI3.exe!winrt::impl::factory_cache_entry<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics>::call<void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) &>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) & callback) Line 6286	C++
 	MyWebView2WinUI3.exe!winrt::impl::call_factory<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics,void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &)>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::void <lambda>(const winrt::Microsoft::UI::Xaml::IApplicationStatics &) && callback) Line 6309	C++
 	MyWebView2WinUI3.exe!winrt::Microsoft::UI::Xaml::Application::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 12147	C++
 	MyWebView2WinUI3.exe!wWinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, wchar_t * __formal, int __formal) Line 69	C++
 	MyWebView2WinUI3.exe!invoke_main() Line 123	C++
 	MyWebView2WinUI3.exe!__scrt_common_main_seh() Line 288	C++
 	MyWebView2WinUI3.exe!__scrt_common_main() Line 331	C++
 	MyWebView2WinUI3.exe!wWinMainCRTStartup(void * __formal) Line 17	C++
 	kernel32.dll!BaseThreadInitThunk�()	Unknown
 	ntdll.dll!RtlUserThreadStart�()	Unknown

@gabbybilka gabbybilka added bug Something isn't working area-WebView labels Nov 10, 2022
@lyahdav
Copy link

lyahdav commented Nov 14, 2022

I just tried upgrading to WinAppSDK 1.2 (non-preview) and I get the same crash. What's odd is that the WinUI 3 Gallery app has a WebView2 example which works fine with WinAppSDK 1.2.

@asklar
Copy link
Member

asklar commented Nov 14, 2022

I get this crash with 1.2 and just a TextBox.

@lyahdav
Copy link

lyahdav commented Nov 15, 2022

@asklar What Windows version are you on? I'm on Win 10 21H2 (19044) and I'm also able to repro with TextBox. I'm wondering if this is a Win 10 only issue.

@asklar
Copy link
Member

asklar commented Nov 15, 2022

This is on windows 11. I'm talking to the folks on the team, @codendone is investigating.

@asklar
Copy link
Member

asklar commented Nov 15, 2022

this looks like a bug in imm32 where it doesn't properly reinitialize itself if it is loaded, unloaded, then re-loaded.

The fix is to not unload it in the first place. The unload happens "for free" in generated code, so to work around it for the time being:

In pch.h, add:

#define DISABLE_XAML_GENERATED_MAIN

Then in app.xaml.cpp, add:

int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
  
  {
    void (WINAPI * pfnXamlCheckProcessRequirements)();
    auto module = ::LoadLibrary(L"Microsoft.ui.xaml.dll");
    if (module)
    {
      pfnXamlCheckProcessRequirements = reinterpret_cast<decltype(pfnXamlCheckProcessRequirements)>(GetProcAddress(module, "XamlCheckProcessRequirements"));
      if (pfnXamlCheckProcessRequirements)
      {
        (*pfnXamlCheckProcessRequirements)();
      }

      // ::FreeLibrary(module);
    }
  }
  

  winrt::init_apartment(winrt::apartment_type::single_threaded);
  ::winrt::Microsoft::UI::Xaml::Application::Start(
    [](auto&&)
    {
      ::winrt::make<::winrt::CompletionControlTest::implementation::App>();
    });

  return 0;
}

Note the call to FreeLibrary is commented out. This avoids unloading imm32 which works around the bug for the time being.

@lyahdav
Copy link

lyahdav commented Nov 15, 2022

@asklar any idea under what conditions this crash occurs? I have a WinUI 3 app where I have that FreeLibrary uncommented and it's working fine with TextBox. One difference is I'm creating the TextBox programmatically in C++ vs declaratively in a .xaml file.

@asklar
Copy link
Member

asklar commented Nov 15, 2022

@lyahdav if imm32 gets loaded before XAML by something else (e.g. user32, or you manually link to it, etc.), then the bug wouldn't repro. The bug happens when imm32 gets unloaded because the only outstanding loader reference gets released.

@TripleSM
Copy link

For us it was becoming a blocker issue to migrating to WinAppSDK 1.2. Thank you verymuch @asklar for the temporary solution.

@gabbybilka
Copy link
Member

🎉Microsoft.WindowsAppSDK.1.2.221116.1 has been released which fixes this issue.

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants