【发布时间】:2011-07-31 19:25:38
【问题描述】:
我已经阅读了很多关于此的内容 - 我觉得我非常接近答案。我只是想从我创建的 dll 文件中调用一个方法。
例如目的:
我的 DLL 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExampleDLL
{
class Program
{
static void Main(string[] args)
{
System.Windows.Forms.MessageBox.Show(args[0]);
}
public void myVoid(string foo)
{
System.Windows.Forms.MessageBox.Show(foo);
}
}
}
我的应用程序:
string filename = @"C:\Test.dll";
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom(filename);
// Obtain a reference to a method known to exist in assembly.
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("myVoid");
// Obtain a reference to the parameters collection of the MethodInfo instance.
以上 sn-p 的所有功劳都归于 SO 用户 'woohoo' How to call a Managed DLL File in C#?
不过,现在,我希望不仅能够引用我的 Dll(以及其中的方法),而且能够正确调用其中的方法(在这种情况下,我想调用方法“myVoid”)。
有人对我有什么建议吗?
谢谢,
埃文
【问题讨论】:
-
为什么不将其引用添加到您的应用程序中?
-
@SaberAmani:因为如果用户有权访问该功能,OP 可能只想包含 DLL。添加的参考必须始终随应用一起提供。
-
在某些情况下,您需要单独发布同一应用程序的模块。初始安装包含基本功能,而升级包使用基本功能 dll 访问某种数据上下文,而无需在升级包中重写相同的代码。
标签: c# dll assemblies