基于代理反射的c#统一调用方法

基于代理反射的c#统一调用方法,c#,exception,reflection,proxy,aop,C#,Exception,Reflection,Proxy,Aop,我被一个问题绊住了。我有这样一段代码: ITest test= ObtainObject(); //ObtainObjectimplementation omitted Type type = test.GetType(); MethodInfo method = type.GetMethod("Display"); method.Invoke(test, new object[] {"hi"}); interface ITest { [LoggerAspect] Displa

我被一个问题绊住了。我有这样一段代码:

ITest test= ObtainObject(); //ObtainObjectimplementation omitted
Type type = test.GetType();
MethodInfo method = type.GetMethod("Display");
method.Invoke(test, new object[] {"hi"});

interface ITest {
    [LoggerAspect]
    Display(String msg);
}

class Test : ITest 
{
    public void Display(String msg) 
    {
        MessageBox.Show(msg);   
    }
}
问题是当我替换

method.Invoke(test, new object[] {"hi"});

一切都很好,包括aspect。测试是一个代理对象,如果我调用该代理上的调用,它会抛出我

TargetException: Object does not match target type
问题是我需要反思,你们中有人曾经遇到过这样的问题吗?
感谢您的建议

为什么界面中的
显示
方法没有定义任何返回类型?我认为这根本不应该被编译


你也应该考虑显示<代码>获取对象< /代码>代码,这样我们就可以确切地知道你是如何获取接口的。除此之外,我想我不能做太多。

显示方法是void类型-我只是在这里写错了。。。AcquinObject的功能如下:ITest-AcquinObject(){return Program.UnityContainer.Resolve();}并从unity上下文获得代理对象-这很好,但当我尝试使用反射在该方面调用方法时,它不起作用…我刚刚测试了您的代码,它似乎运行正常,我现在唯一能想到的是,您可能以错误的方式将类强制转换到接口。这是我的密码:
TargetException: Object does not match target type