当我在其他项目中反序列化时,程序集异常
本文关键字:程序集 异常 反序列化 其他 项目 | 更新日期: 2023-09-27 18:31:23
我有一个程序可以序列化我的类的对象列表。在另一个程序中,我创建了相同的类并且都运行良好。但是昨天我更改了序列化程序的程序集名称,现在我无法反序列化任何文件,因为我有一个例外"不可能找到程序集"......"版本"..."我该如何解决这个问题?我序列化是这样:
public static void serialize(BodyCustom[] bodySerialized, String path)
{
FileStream stream = null;
try
{
BinaryFormatter bFormatter = new BinaryFormatter();
stream = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
bFormatter.Serialize(stream, bodySerialized);
}
catch (Exception ex)
{
ex.ToString();
}
finally
{
if (stream != null)
stream.Close();
}
和反序列化:
public static BodyCustom[] deserialize(String path)
{
BodyCustom[] bodyDeserialized = null;
FileStream stream = null;
try
{
BinaryFormatter bFormatter = new BinaryFormatter();
stream = File.Open(path, FileMode.Open);
bodyDeserialized = (BodyCustom[])bFormatter.Deserialize(stream);
}
catch (Exception ex)
{
ex.ToString();
}
if (stream != null)
stream.Close();
return bodyDeserialized;
}
这是例外:
$exception {"Impossibile to find assembly 'FitnessRecordingUtility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."} System.Exception {System.Runtime.Serialization.SerializationException}
我已经解决了。我已经创建了一个具有类 BodyCustom 的 DLL,具有第一个项目的相同程序集,并且我已经在第二个项目的引用之间导入了它。非常感谢 –