Search code examples
c#stack-overflow

Type.GetType() throwing a StackOverflowException


I have a problem where this code

Type.GetType("Fully qualified assembly name goes here");

But get an uncatchable StackOverflowException.

I have managed to instantiate the class from the fully qualified assembly name but get this error when calling GetType with the same name.

To add to this I have watched the offending line of code work in some cases and not in others, with the exact same fully qualified assembly name in both cases.

This is my first StackOverflow question so comments on the structure of it are welcome. :)


Solution

  • Here are some relevant sounding pieces of information that may help from http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx :

    To determine if there is a problem with your assembly try this:

    GetType causes loading of the assembly specified in typeName. You can also load an assembly using the Load method, and then use the GetType or GetTypes methods of the Assembly class to get Type objects.

    If you get an error on Load(assembly) then you know the problem isn't with the GetType() call.

    Also, make sure you're passing in the right type of assembly:

    GetType only works on assemblies loaded from disk. If you call GetType to look up a type defined in a dynamic assembly defined using the System.Reflection.Emit services, you might get inconsistent behavior.