dll をロードしてインスタンスを作成し、メソッドを呼び出して戻り値を確認したいと考えています。インスタンスの作成時に、例外 {"Parameter count mismatch."} が発生します。
static void Main(string[] args)
{
ModuleConfiguration moduleConfiguration = new ModuleConfiguration();
// get the module information
if (!moduleConfiguration.getModuleInfo())
throw new Exception("Error: Module information cannot be retrieved");
// Load the dll
string moduledll = Directory.GetCurrentDirectory() + "\\" +
moduleConfiguration.moduleDLL;
testDLL = Assembly.LoadFile(moduledll);
// create the object
string fullTypeName = "MyNameSpace."+ moduleConfiguration.moduleClassName;
Type moduleType = testDLL.GetType(fullTypeName);
Type[] types = new Type[1];
types[0] = typeof(string[]);
ConstructorInfo constructorInfoObj = moduleType.GetConstructor(
BindingFlags.Instance | BindingFlags.Public, null,
CallingConventions.HasThis, types, null);
if (constructorInfoObj != null)
{
Console.WriteLine(constructorInfoObj.ToString());
constructorInfoObj.Invoke(args);
}
The constructor for the class in dll is:
public class SampleModule:ModuleBase
{
/// <summary>
/// Initializes a new instance of the <see cref="SampleModule" /> class.
/// </summary>
public SampleModule(string[] args)
: base(args)
{
Console.WriteLine("Creating SampleModule");
}
Q: 1. 何が間違っていますか? 2. メソッドを取得して呼び出し、戻り値を取得するにはどうすればよいですか? 3.これを行うためのより良い方法はありますか?