【问题标题】:Execute method inside signed console app from an unsigned assembly by Reflection通过反射从未签名的程序集中在签名的控制台应用程序中执行方法
【发布时间】:2014-12-15 13:15:19
【问题描述】:

首先,

很抱歉我对 .net 和所有的一切都一无所知,我已经使用它很长时间了,但我仍在学习中,这就是我要问的方式。

我正在学习反射,并且在尝试以下方法时正在练习:

我添加了对已签名程序集的未签名引用,一切正常;编译器说引用没有一个强名称(这是我所期望的)。

但是当我使用MethodInfo.Invoke(null, null) 调用静态方法时,它工作得很好。

我通过配置标签页签署了项目(只是控制台之一)。

我不明白,谁能给我解释一下

问题是:

如果程序集未签名,为什么在通过反射调用时在已签名的程序集中工作。

谢谢,

我的代码

来自唯一类签名程序集(控制台应用程序)项目的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Assembly a = Assembly.LoadFrom(
                @"path\ClassLibrary1.dll");

          var m= a.GetType("ClassLibrary1.ZZ");
          MethodInfo met = m.GetMethod("TroskisTroskis");
          met.Invoke(null,null);


           Console.ReadKey(true);
        }
    }
}

来自唯一类非签名汇编项目的代码:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ClassLibrary1
{
    public  static class ZZ
    {
        public  static void TroskisTroskis()
        {
            Thread.Sleep(1000);
        }
    }
}

谢谢

【问题讨论】:

  • 你不明白什么?好像您发布了工作代码...!?
  • 它一定不行,它没有签名
  • 不是重复问题,而是正确答案here
  • 谢谢,我明白了一点。

标签: c# reflection sign


【解决方案1】:

已签名的程序集不能引用未签名的程序集,但它可以后期绑定到一个(加载它)。

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 2011-05-19
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多