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

Failed to compile with NativeAOT .NET 7.0 #48

Closed
xoofx opened this issue Dec 20, 2022 · 6 comments
Closed

Failed to compile with NativeAOT .NET 7.0 #48

xoofx opened this issue Dec 20, 2022 · 6 comments

Comments

@xoofx
Copy link

xoofx commented Dec 20, 2022

Hey,

I was trying to use it on a .NET 7 + NativeAOT and dotnet publish generates the following warning:

ILC: Method '[SimpleProgramChange]SimpleProgramChange.SimpleProgramChangeController.CreateView()' will always throw because: Failed to load assembly 'System.Windows.Forms'

And it crashes at runtime indeed.

I had also to remove the initialization of WinFormsComInterop (Package 0.3.2) as I saw it here

Any clue?

@kant2002
Copy link
Owner

kant2002 commented Dec 20, 2022

SampleWindowsForms was a bit outdated. I did update sample, but mostly you need just what's in the README.md. Couple questions

  • Are you using net7.0-windows?
  • is it possible that you have dependency on other library?

@xoofx
Copy link
Author

xoofx commented Dec 20, 2022

Are you using net7.0-windows?

Yep.

is it possible that you have dependency on other library?

I was using directly winforms and the UserControl, so pretty basic.

But don't worry, that was for testing. Probably not gonna use winforms anyway.

I will close it for now. Thanks!

@xoofx xoofx closed this as completed Dec 20, 2022
@kant2002
Copy link
Owner

That's pretty strange, since I did try that on different apps, and never seen this issue.
Also to let you know that I soon will have update for WinForms + WebView2 + Blazor, so maybe that would be more interesting to you.

@kant2002
Copy link
Owner

Also what OS you are try to compile? I assume that's windows?

@xoofx
Copy link
Author

xoofx commented Dec 20, 2022

Also what OS you are try to compile? I assume that's windows?

Yeah, Windows.

That's pretty strange, since I did try that on different apps, and never seen this issue.
Also to let you know that I soon will have update for WinForms + WebView2 + Blazor, so maybe that would be more interesting to you.

My setup is a bit unusual, as it was to test this within a NativeAOT library (and not an exe), though I would not think that would matter, the error is coming from ILC, like it's not even able to locate the assembly, dunno, but weird... anyway, I don't want to bother you with this! 😉

@kant2002
Copy link
Owner

kant2002 commented Jan 8, 2023

Take a look at this sample https://github.com/kant2002/WinFormsComInterop/tree/main/samples/HostedWindowsForms. I think you was missing --self-contained when publish application.

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

2 participants