本文介绍了获取程序集中的类型(错误:System.Reflection.ReflectionTypeLoadException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的异常类型为异常详细信息:System.Reflection.ReflectionTypeLoadException:无法加载一种或多种请求的类型.检索LoaderExceptions属性以获取更多信息.使用以下代码:

I'm receiving an Exception of type "Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." with the following code:

public IEnumerable<Type> FindClassesOfType(Type assignTypeFrom, IEnumerable<Assembly> assemblies, bool onlyConcreteClasses = true)
    {
        foreach(var a in assemblies)
        {
            foreach (var t in a.GetTypes())

我需要获取每个程序集中定义的类型,但似乎无法生成.

I need to Get the Types defined in each assembly but it seems that it cannot be generated.

我已经通过删除dll,干净的解决方案,重新加载解决方案等执行了所有与错误的程序集相关的典型过程,但是什么都没有发生.

I already performed all typical procedures related to wrong assembly creating by deleting dll´s, clean solution, reload solution, etc but nothing happened.

我想提出一些想法,以便通过找到一种方法来检索更多有关错误的信息,或者找到哪个程序集正在产生问题或类似的问题来解决该问题.当前的异常消息非常模糊,以至于无法确定是哪个问题.

I would like to request ideas in order to solve this problem by finding a way to retrieve more information of the error, or find which assembly is generating problems or something like that. The current exception message is so vague to realize which is the problem.

ps:其他信息,当我运行重建操作时,所有进程均正确生成,没有错误.

ps: additional info, when I run the rebuild action all process are correctly generated with no errors.

推荐答案

错误消息说明了您真正需要的一切:

The error message says everything you need, really:

try {
    // your code
} catch (ReflectionTypeLoadException ex) {
    // now look at ex.LoaderExceptions - this is an Exception[], so:
    foreach(Exception inner in ex.LoaderExceptions) {
        // write details of "inner", in particular inner.Message
    }
}

这篇关于获取程序集中的类型(错误:System.Reflection.ReflectionTypeLoadException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 23:31