In assembly, get Types (error: System.Reflection.ReflectionTypeLoadException)

asp.net-mvc c# entity-framework system.reflection

Question

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
16
5/22/2011 7:26:30 AM

Accepted Answer

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
    }
}
22
5/22/2011 7:48:35 AM

Popular Answer

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



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow