在'Assembly'中找不到DefinedTypes。你错过了任何参考

时间:2016-06-17 07:03:02

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

我使用反射来根据字符串方法和类名动态调用方法。为此,我遍历所有程序集以找到给定的类名并调用其中的方法。循环遍历下面的程序集

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”。

1 个答案:

答案 0 :(得分:2)

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