ReflectionTypeLoadException

If a type can't be loaded for some reason during a call to Module.GetTypes(), ReflectionTypeLoadException will be thrown. Assembly.GetTypes() also throws this because it calls Module.GetTypes().

The Message for this exception is "One or more exceptions have been thrown while loading the types" or "Unable to load one or more of the types in the assembly", which doesn't seem very descriptive. But, the exception actually provides more info that that. Just get the LoaderExceptions property of the ReflectionTypeLoadException instance. That will give an array of the exceptions caught while loading all of the types from the module. If the exceptions are due to an assembly loading problem, see my general debugging advice.

Comments

  • Anonymous
    August 12, 2003
    If you get this exception, the first thing to check is whether you made a typo (or rather an intellisenso) and used Assembly.LoadFile instead of Assembly.LoadFrom.

  • Anonymous
    July 28, 2005
    Thanks sooo much for the advice about using LoadFrom istead!!! of LoadFile! Worked awesome

  • Anonymous
    December 08, 2005
    Great advice suzcook. After looking at the LoaderExceptions I found that I was missing a couple References in my project. The solution built because the references were not needed until run time.

    Thanks Again

  • Anonymous
    April 05, 2006
    Hi Suzanne,

    I have a problem with dynamically loading an assembly which is refering to another assembly. That assembly is loaded in GAC but unfortunately there is a reference missing in the assembly loaded in GAC.

    When I try to use oAssembly.GetTypes(). Error I am getting is ReflectionTypeLoadException Error. I have checked the LoaderExceptions error there is FileNotFound exception.

    What I want is to load all types and its method and properties. In the same way as it loads in the VS.Net Object Browser. Is this possible?

    Coz, the same assembly's Type, Methods, Properties and fields are displayed by the Object Browser.

    Regards,
    Pankil

  • Anonymous
    April 08, 2006

    I'm trying to fix my ASP.NET application, it's working OK at my development machine, but when I upload it it crashes. I'm unable to use Fusion logs since it's at the host's machine.

    The exception is thrown at Module.GetTypes().

    I've tried to use the LoaderExceptions property, and all I get is several identical messages "System.TypeLoadException: ?" (actually my assembly contains much more types).

    I'm using .NET 1.1

    Could anybody help me with that? Could it be some permissions issue?

    Thanks a lot

    ulu

  • Anonymous
    April 08, 2006
    Well it turned out that I had an old version of a 3rd party dll.

    This is how it can be found out:
    1. Enumerate all your ex.LoaderExceptions
    2. If they are TypeLoadExceptions, look at TypeLoadException.TypeName

    ulu

  • Anonymous
    May 05, 2006
    thank you for the tip with the loaderexceptions. After I extended my logger to watch for those i was able to find "my" culbrit.

  • Anonymous
    July 31, 2006
    The comment has been removed

  • Anonymous
    November 21, 2006
    It's natural for a tool to use Reflection-Only loading to load an assembly and view the types in it.

  • Anonymous
    October 12, 2009
    The comment has been removed

  • Anonymous
    November 02, 2009
    Looking at LoaderExceptions property is a great tip. I also found that some references were missing.