我想加载一个 dll 文件 (Test.dll) 作为程序集。我可以使用直接 Visual Studio 引用(即加载 dll 作为对我的 C# 应用程序的引用)以及使用 Assembly.LoadFile(filename)
方法加载 dll 来执行此操作。现在,我想将我的 dll 文件作为 嵌入式资源 添加到我的 Visual Studio 应用程序中,并将 dll 文件作为程序集加载。我知道如何将此资源作为字节数组加载,字节数组和我可以使用的程序集之间是否存在某种关联?此外,我需要能够调用位于 dll 文件中的方法。请参阅下面的代码 - 它将进一步解释我在做什么。
Assembly SampleAssembly = Assembly.LoadFrom("WindowsFormsApplication2.ThisisaTESTDLL.dll");
Type myType = SampleAssembly.GetTypes()[0];
MethodInfo Method = myType.GetMethod("myVoid");
object myInstance = Activator.CreateInstance(myType,null);
Method.Invoke(myInstance,new object[] { "param1", "param1"});
如果我在这里遗漏任何内容,请恭敬地告诉我,我将编辑原始帖子。
最佳答案
Assembly.GetExecutingAssembly().GetManifestResourceStream(...)
这应该会为您提供一个 Stream 对象。您可以从中读取一个字节数组。
您可以使用 Assembly.Load 加载它
关于c# - 从嵌入式资源加载程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6893060/