【问题标题】:DefinedTypes not found in 'Assembly'. Are you missing any reference在“程序集”中找不到定义的类型。您是否缺少任何参考
【发布时间】:2016-06-17 07:03:01
【问题描述】:

我正在使用反射根据字符串方法和类名动态调用方法。为此,我遍历所有程序集以查找给定的类名并调用其中的方法。在像下面这样循环访问程序集时

foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
    type = asm.DefinedTypes.Where(t => string.Compare(t.Name, pTypeName, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();
    if (type != null) //If the type is found, stop looping through the assemblies
        break;
}

我收到错误“在'Assembly'中找不到DefinedTypes”。

【问题讨论】:

  • 在 .NET 4.5 中添加,以及使该方法成为必需的 TypeInfo 类。请改用 GetTypes()。

标签: c# .net .net-assembly system.reflection


【解决方案1】:

我能够解决这个问题。我的项目面向 .Net 4。当我将目标框架更改为 .Net 4.6 时,问题得到了解决。

【讨论】:

    猜你喜欢
    • 2010-12-08
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    相关资源
    最近更新 更多