.NET Core 2.2组装System.Windows.Forms丢失

问题描述:

我想将.NET Framework 4.0中的项目迁移到.NET Core 2.2。但是我的程序执行中有一个错误。

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.

我的项目想用 Assembly 类加载.dll ,它可以与.NET Framework 4.0一起正常工作,但不能与.NET Core 2.2一起工作。它引发n个异常:

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:调用的目标抛出了异常。 ---> System.IO.FileNotFoundException:无法加载文件或程序集'System.Windows.Forms,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'

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

我需要导入一个兼容.NET Core 2.2与.NET Framework 4.0的 System.Windows.Forms 类似?

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

我的NuGet软件包安装在解决方案:

My NuGet packages installed in Solution:

如何使用System.Windows.Forms的副本在.NET Core类库中

没有Windows窗体(或WPF)。 NET核心。

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

您想要的东西是不可能的

What you want is not possible


(但是使用NET Core中定义的子集以及下一个主要版本)。

如果您列出了要求,也许人们可以建议另一种方法,但是它赢得了不是Windows窗体。

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