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

Infinite Recursion Crash in WPF Window Containing WindowsFormsHost After Upgrading From .NET 6 to .NET 8 #10171

Open
jaybyrd42 opened this issue Dec 12, 2024 · 0 comments
Labels
Investigate Requires further investigation by the WPF team.

Comments

@jaybyrd42
Copy link

Description

After upgrading a WPF application from .NET 6 to .NET 8, windows that contain a WindowsFormsHost element now cause a hard crash when the window is closed. Prior to the upgrade, these windows closed without error on .NET 6.

This issue only arises on windows that include a WindowsFormsHost. If the WindowsFormsHost is removed from the XAML or the entire window, the exception does not occur. No code changes other than upgrading the target framework from .NET 6 to .NET 8 were made.

Explicitly disposing of the WindowsFormsHost on closing resolves the issue.

Exception message: System.InvalidOperationException: Encountered infinite recursion while looking up resource '{key}' in {"System.Private.CoreLib"}. Verify the installation of .NET is complete and does not need repairing, and that the state of the process has not become corrupted.

Reproduction Steps

  • Create a new WPF application targeting .NET 8.
  • Add a WindowsFormsHost control to a WPF Window.
  • Add Forms control to WindowsFormsHost
  • Run the application.
  • Open the window that contains the WindowsFormsHost.
  • Close the window.

Expected behavior

The window should close cleanly without any exceptions, as it did on .NET 6.

Actual behavior

The application throws an unhandled exception and crashes when closing the window containing a WindowsFormsHost on .NET 8.

Regression?

This behaviour was not present in .NET 6.

Known Workarounds

Removing the WindowsFormsHost from the window avoids the crash, but this is not feasible for the full application since we are in the process of migrating Windows Forms code to WPF incrementally.

Targeting .NET 6 instead of .NET 8 also avoids the issue, but we need .NET 8 for new features and performance improvements.

Impact

This issue severely impacts application stability and user experience. Because the crash occurs when closing windows that contain critical embedded Windows Forms components, end-users experience sudden and unexplained application terminations. In a production environment, the crash undermines confidence in the software’s reliability and can negatively affect the application's reputation.

Configuration

No response

Other information

The issue seems to be machine dependant as some users are able to reproduce the exception while others are not. Those that can reproduce can reliably reproduce.

The issue does not appear to be related to any third-party libraries.

We have tried with clean installs of .NET 8 and verified no installation corruption.

The infinite recursion message suggests a resource lookup issue within System.Private.CoreLib, triggered specifically by shutting down a WPF window hosting WinForms controls.

@himgoyalmicro himgoyalmicro added the Investigate Requires further investigation by the WPF team. label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

2 participants