Get Types in assembly (error: System.Reflection.ReflectionTypeLoadException)

非 Y 不嫁゛ 提交于 2019-12-18 19:08:16

问题


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 wich assembly is generating problems or something like that. The current exception message is so vague to realize which is the problem.

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


回答1:


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



回答2:


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




回答3:


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!



来源:https://stackoverflow.com/questions/6086633/get-types-in-assembly-error-system-reflection-reflectiontypeloadexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!