繁体   English   中英

System.MissingMethodException错误

[英]System.MissingMethodException error

我有这段代码

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

谁能帮助我调查问题?

文档中 (请参阅“例外”部分):

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM