1

I want to migrate my project in .NET Framework 4.0 to .NET Core 2.2. But I have an error in my program execution.

My project wants to load a .dll with the Assembly class, it's working fine with .NET Framework 4.0 but not with .NET Core 2.2. It's throwing a n exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

using System.Reflection; // Assembly class

var pathToDll = "../../../../";
var asm = Assembly.LoadFrom(pathToDll);

var callingProgObject = asm.GetType("RandomType.CallingProg");
MethodInfo method = callingProgObject.GetMethod("MethodInDll");

var input = new InputForDll();
method.Invoke(callingProgObject, new object[] {input}); // <-------- error

I need to import one package compatible for .NET Core 2.2 similar to System.Windows.Forms of .NET Framework 4.0?

My NuGet packages installed in Solution:

My NuGet packages installed in Solution

Not duplicate of How to use System.Windows.Forms in .NET Core class library

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Rod
  • 712
  • 2
  • 12
  • 36
  • Did you replace the real values with RandomType and MethodInDll ? Because they are rather crucial here. And what part of your code is calling this (and why) ? – bommelding Oct 25 '18 at 10:38
  • 2
    Winforms isn't supported in .NET Core 2.2. It might be supported in .NET Core 3 though. [link](https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/) – James Cockayne Oct 25 '18 at 10:48
  • Primary focus for .netcore was to make porting to Linux and macOS easy. That can't work for Winforms, those OSes are far too different. I haven't see a lot of praise for Mono's attempt to do this. Consider Xamarin if you need a GUI that runs on .netcore. Or wait until .netcore 3 gets stable, if porting is not important, that will take a while. No rush, .netframework is just fine. – Hans Passant Oct 25 '18 at 11:59

3 Answers3

3

There is no Windows Forms (or WPF) for .NET Core.

What you want is not possible

(but might be possible with a defined subset of .NET Core with the next major version)

If you list your requirements, maybe people can suggest another way to do it, but it won't be Windows Forms.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • 1
    I don't think the OP wants to run WinForms, it's obviously an ASP.NET Core project. With some obscure component still wanting to use something from Windows.Forms, like maybe `Color` or `Rect` – bommelding Oct 25 '18 at 12:09
  • 3
    Then why did you accept this answer? That sends the wrong message. – bommelding Oct 26 '18 at 11:43
2

Currently the Windows.Forms is not supported on .NET core.

You can refer to this answer for alternate ways of creating GUI in .NET core.

B45i
  • 2,368
  • 2
  • 23
  • 33
0

Just add

<UseWindowsForms>true</UseWindowsForms>

to your .csproj file

Eimaaa
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 10 '22 at 11:50