I need to deserialize classes created on different machines.
The programs are very similar but have differences in Program name, as well as .Net version etc.
This code below works quite well, except for when I have a Queue in my class. I am unable to search the exsting assemblies to find something suitable.
public override Type BindToType(string assemblyName, string typeName)
{
string typeSearchString;// = typeName.Split('+')[1];
try
{
typeSearchString = typeName.Split('+')[1];
}
catch
{
var parts = typeName.Split(new string[] { "[[" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(',');
typeSearchString = @"System.Collections.Generic.Queue"; //This does NOT find Queue<Double> but it does find something else which gives an error
}
Type tyType = null;
string sShortAssemblyName = assemblyName.Split(',')[0];
System.Reflection.Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (System.Reflection.Assembly ayAssembly in ayAssemblies)
{
foreach (Type type in ayAssembly.GetTypes())
{
if (type.FullName.Contains(typeSearchString))
{
tyType = ayAssembly.GetType(type.FullName);
return tyType;
}
}
}
return tyType;
}
EDIT 1
This is what I have to create a search from:
typeName = "System.Collections.Generic.Queue`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"