簡體   English   中英

Activator.CreateInstance期間缺少MissingMethodException

[英]MissingMethodException during Activator.CreateInstance

我有一個帶有該構造函數的Form類:

public partial class PackageForm : Form
{
    Responder MfwuResp;

    public PackageForm()
    {
        MfwuResp = new Responder(new Responder.CancelHandler(StopMethod), true);
    }

    public void StopMethod(Responder responder)
    {
        Console.WriteLine("Cancel Update");
    }
}

我在單獨的文件中也有一個Responder類

public class Responder 
{
    Type[] types;
    Object resp;

    public Responder(Responder.CancelHandler handler, bool isCancellable)
    {
        BinaryReader reader = new BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Update.Resources.AppUpdate.dll"));

        byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);

        Assembly assm = Assembly.Load(bytes);

        types = assm.GetExportedTypes();

        resp = Activator.CreateInstance(types[0], new object[] { handler, isCancellable });

    }

    public delegate void CancelHandler(UtilityResponder responder);
}

每當我在Main中創建一個新的PackageForm時,都會收到MissingMethodException

找不到類型為'AppUpdate.Responder'的構造方法。

知道為什么會這樣嗎? 我想語法上沒有問題,因為存在CreateInstance的構造函數,該構造函數將Type和params object []作為參數。

注意:Responder類是從外部dll文件AppUpdate.dll引用的。

首先,您完全確定types僅包含PackageForm嗎?

無論如何,當它只有一個默認構造函數(無參數)時,您嘗試使用構造函數參數創建PackageForm

您可能只想打電話給這個

resp = (Form)Activator.CreateInstance(types[0]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM