获取程序集中的类型(错误:System.Reflection.ReflectionTypeLoadException)

发布于 2024-11-08 18:40:13 字数 616 浏览 0 评论 0原文

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

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

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

我已经通过删除 dll、清理解决方案、重新加载解决方案等执行了与创建错误程序集相关的所有典型程序,但什么也没发生。

我想请求一些想法,以便通过找到一种方法来检索错误的更多信息,或者找到哪个程序集产生问题或类似的问题来解决这个问题。当前的异常消息非常模糊,无法意识到问题所在。

ps:附加信息,当我运行重建操作时,所有进程都正确生成,没有错误。

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.

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: additional info, when I run the rebuild action all process are correctly generated with no errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空袭的梦i 2024-11-15 18:40:13

错误消息确实说明了您需要的一切:

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
    }
}

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
    }
}
温柔戏命师 2024-11-15 18:40:13

如果您使用实体框架,请检查 Web.Config 中的版本是否与您的项目中引用的版本相同。

If you use the Entity Framework, check if version in Web.Config is the same referenced in your project.

执笏见 2024-11-15 18:40:13

DLL是你创建的吗?您的目标是哪个框架?

我刚刚遇到了这个问题。即使使用框架 3.5(使用 CLR2)编译我的外部库,也无法导入 DLL。错误和你的一样。我已经解决了重建针对框架 3.0 的库的问题,并且现在似乎可以工作。我将 dll 留在 Plugins 文件夹中,没有任何问题。

Unity 论坛中有很多类似的问题。

也许您已经有了解决方案,但这可以帮助将来需要它的任何人(就像我需要的那样)。

此致!

Was the DLL created by you? Which framework are you targeting?

I've faced this problem just now. Even compiling my external libs with framework 3.5 (that uses CLR2), the DLL coudn't be imported. The error was the same as yours. I've solved my problem rebuilding my libs targeting framework 3.0 and seems to work now. I'm leaving my dlls in Plugins folder with no problems.

There are lots of similar problems in Unity forums.

Maybe you have the solution already, but this can help anyone who needs it in the future (like I needed).

Best Regards!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文