从表单执行模块时出错 [英] Error while executing Module from Form

查看:58
本文介绍了从表单执行模块时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Module Module1

    Public Sub main()
        Dim a As System.Reflection.Assembly = System.Reflection.Assembly.Load(IO.File.ReadAllBytes("C:\myProgram.exe"))
        Dim method As System.Reflection.MethodInfo = a.EntryPoint
        Dim o As Object = a.CreateInstance(method.Name)
        method.Invoke(o, New Object() {New String() {"1"}})
    End Sub
End Module


Public Class Form1

Sub start()
Module.main()
End Sub


问题是,当我制作一个控制台应用程序并在module1中启动main()子程序时,它可以工作,但是从Form1尝试时它会抛出类似以下的错误:


The Problem is when i make a console application and start the main() sub in module1 it works but trying from Form1 it throws error like;

Exception has been thrown by the target of an invocation.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll


到目前为止,我认为该代码仅在控制台应用程序中有效,如何自定义此代码以使其在窗体中运行(Windows应用程序)
感谢任何帮助,谢谢


So far i think this code works only in a console application, how do customize this code to be ran in a form (windows application)
Any help appreciated, thanks

推荐答案

这仅表示您在方法method中有一个异常,并且由于调用,该异常信息看起来如此奇怪且不完整机制.确定实现它的方法(这是已加载程序集的入口点),在其上放置一个断点(您应该拥有它的源代码;并且它的项目应该在相同的解决方案中),然后运行您所需要的应用程序展示.您应该能够执行负责此问题的代码并找到它.



顺便说一句,一旦将文件放在光盘上,而不仅仅是字节,这是一种非常奇怪的程序集加载方式.您不必读取文件.而是使用方法System.Reflection.Assembly.LoadFrom:
http://msdn.microsoft.com/en-us/library/1009fa28.aspx [ ^ ].

—SA
It simply means you have an exception in the method method, and the exception information looks so strange and incomplete, because of the invocation mechanism. Identify the method where it is implemented (this is the entry point of the loaded assembly), put a break point on it (you should have its source code; and its project should be in the same solution), and run the application which you show. You should be able to execute the code responsible for this problem and locate it.



By the way, this is a very strange way of loading of the assembly, once you have the file on the disc, not just bytes. You don''t have to read the file. Instead, use the method System.Reflection.Assembly.LoadFrom:
http://msdn.microsoft.com/en-us/library/1009fa28.aspx[^].

—SA


这篇关于从表单执行模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆