kant2002 / WinFormsComInterop

ComWrappers required to run NativeAOT and WinForms
MIT License
225 stars 31 forks source link

Failed to compile with NativeAOT .NET 7.0 #48

Closed xoofx closed 1 year ago

xoofx commented 1 year ago

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 commented 1 year ago

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

xoofx commented 1 year ago

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!

kant2002 commented 1 year ago

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 commented 1 year ago

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

xoofx commented 1 year ago

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 commented 1 year ago

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.