System.Runtime.Serialization.SerializationException:“无法找到程序集“Global, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”。”
新建一个类UBinder
:
public class UBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
// 从E:\TibetGlobal.dll读取
var path = Path.Combine("E:\\", "TibetGlobal.dll");
var assembly = Assembly.LoadFrom(globalPath);
return assembly.GetType(typeName);
}
}
}
使用这个类
var formatter = new BinaryFormatter
{
Binder = new UBinder()
};
var obj = formatter.Deserialize(pipeServer);