Vb.net System.Assembly.Load()错误

Vb.net System.Assembly.Load()错误,vb.net,Vb.net,因此,我尝试使用Assembly.load()加载Windows窗体应用程序,当字节尝试运行时,它会抛出以下错误: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: SetCompatibleTextRenderingDefault must be calle

因此,我尝试使用Assembly.load()加载Windows窗体应用程序,当字节尝试运行时,它会抛出以下错误:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
at System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(Boolean defaultValue)
at CrypterTestFile.My.MyApplication.Main(String[] Args)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Test.Module1.Main() in C:\Users\Jeffrey\AppData\Local\Temporary Projects\Test\Module1.vb:line 15
这是我的密码:

Dim entryPoint As MethodInfo = Assembly.Load(IO.File.ReadAllBytes(OFD.FileName)).EntryPoint
If entryPoint.GetParameters().Length = 0 Then
    entryPoint.Invoke(Nothing, Nothing)
Else
    entryPoint.Invoke(Nothing, New Object() {New String() {"0"}})
    'Error is being thrown ^
End If

我不知道为什么会发生这种情况,但这只是一个简单的Windows窗体应用程序,它的中心有一个标签。

问题是您试图加载一个作为独立EXE程序编写的Winforms程序。使用初始化Winforms的Main()方法。问题是,这已经由您自己的程序完成了。它只能初始化一次。这件事没有简单的解决办法,总得有人当老板。汉斯·帕桑是对的。我修复了这个错误,用CodeDom编译代码,然后正确执行。谢谢你的帮助。