【问题标题】:System.MissingMethodException errorSystem.MissingMethodException 错误
【发布时间】:2015-12-01 19:36:41
【问题描述】:

我有这段代码

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DotNetOpenAuth.dll");
Assembly assembly = Assembly.LoadFile(path);
Type type = assembly.GetType("DotNetOpenAuth.OAuth2.UserAgentClient");

if (type != null) 
{
    MethodInfo methodInfo = type.GetMethod("ProcessUserAuthorization");

    if (methodInfo != null)
    {
        object result = null;
        ParameterInfo[] parameters = methodInfo.GetParameters();
        object classInstance = Activator.CreateInstance(type);

        if (parameters.Length == 0)
        {
            result = methodInfo.Invoke(classInstance, null);
        }
        else
        {
            object parametersArray = new object[] { "One", "Two" };

            result = methodInfo.Invoke(methodInfo, parametersArray);
        }
    }
}

上线

object classInstance = Activator.CreateInstance(type);

我收到一个错误

System.MissingMethodException

谁能帮我看看这个问题?

【问题讨论】:

标签: c#


【解决方案1】:

来自docs(参见“例外”部分):

没有找到匹配的公共构造函数。

因此,您要么需要DotNetOpenAuth.OAuth2.UserAgentClient 中的公共无参数构造函数,要么必须使用另一个CreateInstance 重载并提供参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多