private static Type LoadTypeWithPartialName(ITypeName typeNameInfo, Assembly initialAssembly, string fullTypeName)
{
Type type2;
uint nameCount = typeNameInfo.GetNameCount();
uint typeArgumentCount = typeNameInfo.GetTypeArgumentCount();
IntPtr[] ptrArray = new IntPtr[nameCount];
IntPtr[] ptrArray2 = new IntPtr[typeArgumentCount];
try
{
Type nestedType = null;
if (nameCount == 0)
{
throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
}
GCHandle handle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
nameCount = typeNameInfo.GetNames(nameCount, handle.AddrOfPinnedObject());
handle.Free();
string name = Marshal.PtrToStringBSTR(ptrArray[0]);
string assemblyName = typeNameInfo.GetAssemblyName();
if (!string.IsNullOrEmpty(assemblyName))
{
Assembly assembly = Assembly.LoadWithPartialName(assemblyName);
if (assembly == null)
{
assembly = Assembly.LoadWithPartialName(new AssemblyName(assemblyName).Name);
}
nestedType = assembly.GetType(name);
}
else if (initialAssembly != null)
{
nestedType = initialAssembly.GetType(name);
}
else
{
nestedType = Type.GetType(name);
}
if (nestedType == null)
{
throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
}
for (int i = 1; i < nameCount; i++)
{
string str3 = Marshal.PtrToStringBSTR(ptrArray[i]);
nestedType = nestedType.GetNestedType(str3, BindingFlags.NonPublic | BindingFlags.Public);
if (nestedType == null)
{
throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
}
}
if (typeArgumentCount != 0)
{
GCHandle handle2 = GCHandle.Alloc(ptrArray2, GCHandleType.Pinned);
typeArgumentCount = typeNameInfo.GetTypeArguments(typeArgumentCount, handle2.AddrOfPinnedObject());
handle2.Free();
Type[] typeArguments = new Type[typeArgumentCount];
for (int j = 0; j < typeArgumentCount; j++)
{
typeArguments[j] = LoadTypeWithPartialName((ITypeName) Marshal.GetObjectForIUnknown(ptrArray2[j]), null, fullTypeName);
}
return nestedType.MakeGenericType(typeArguments);
}
type2 = nestedType;
}
finally
{
for (int k = 0; k < ptrArray.Length; k++)
{
IntPtr ptr1 = ptrArray[k];
Marshal.FreeBSTR(ptrArray[k]);
}
for (int m = 0; m < ptrArray2.Length; m++)
{
IntPtr ptr2 = ptrArray2[m];
Marshal.Release(ptrArray2[m]);
}
}
return type2;
}