0
votes

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

2
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
Winforms isn't supported in .NET Core 2.2. It might be supported in .NET Core 3 though. link - James Cockayne
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

2 Answers

2
votes

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.

2
votes

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.