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

wpf throw Could not load file or assembly 'System.Windows.Forms exception on starting if published with --self-contained #10108

Open
alraseensaad opened this issue Nov 22, 2024 · 0 comments

Comments

@alraseensaad
Copy link

Description

When I run the wpf application it throw
Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
if any third party need System.Windows.Forms when I publish the application using --self-contained and works fine if --self-contained=false

Reproduction Steps

Create a new wpf project and references it for example Microsoft.AppCenter which requires System.Windows.Forms

configure the AppCenter on startup

 public partial class App : Application
 {
     public App()
     {
         Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
     }

     private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
     {
         MessageBox.Show(e.Exception.Message);
     }

     protected override void OnStartup(StartupEventArgs e)
     {
         base.OnStartup(e);
         SetAppCenter();
     }
     private void SetAppCenter()
     {
         Microsoft.AppCenter.AppCenter.Start("null",
                    typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Crashes));

     }

 }

Expected behavior

To run normally like self-contained=false publishing

Actual behavior

It throws exception
Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

Regression?

It works if I publish the using self-contained=false

Known Workarounds

No response

Impact

No response

Configuration

dotnet 9
windows 11
x64

Other information

WpfApp9-master.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant