Step 1 - Get an instance of type:
You need to use the qualified assembly name passed to Type.GetType() . Performing a quick test by calling GetType().AssemblyQualifiedName in an instance of type Dictionary (), it turns out:
System.Collections.Generic.Dictionary`2 [[System.String, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089], [System.String, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]], mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089
quite a mess. I believe that you can remove most of them, although it will still work:
System.Collections.Generic.Dictionary`2 [[System.String, mscorlib], [System.String, mscorlib]], mscorlib
for this:
var typeName = "System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.String, mscorlib]], mscorlib"; var type = Type.GetType( typeName );
Step 2 (assuming the API forces a common parameter that IMO is shit) - Use reflection to parameterize the dynamic generic method:
var genericMethod = typeof(Serialzier).GetMethod( "Deserializer" ); var parametizedMethod = genericMethod.MakeGenericMethod( type ); var parameters = new object[] { _stream }; var deserializedInstance = parametizedMethod.Invoke( null, parameters );