In an assembly loaded into the current AppDomain using Assembly.LoadFrom, I have the following code:
[TypeConverter(typeof(EnumConverter<Shapes>))] public enum Shapes { Triangle, Square, Circle }
The generic EnumConverter<T> is defined in the assembly returned by calling Assembly.GetEntryAssembly(). When I read the TypeConverter attribute at runtime, I get the full name of the type which looks something like:
MyAssembly.EnumConverter`1[[MyDynamicAssembly.Shapes, MyDynamicAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
However, when I call Type.GetType() on the string, it returns null. I expected to be able to get an instance of System.Type. Also note that MyDynamicAssembly was not generated by Reflection.Emit (pointed out in the MSDN article here).
This code was generated on Visual Studio 2005 using .NET Framework 2.0.
Has anyone found a workaround for this bug/limitation? Has it been fixed in 3.5?
After following a lead from an MSDN forum posting, I was able to put together a general solution for loading arbitrary generic types from assemblies loaded at runtime. I hope this helps some people (and maybe Microsoft will put something equivalent into .NET 4.0?)
This code was tested both with the scenario above, and with the following MbUnit test:
Note: You should comment out the trivial handler when trying to use this test, otherwise Type.GetType() will be called instead of the actual parsing code.