所以我试图用 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 窗体应用程序,它的中心有一个标签。