private void button1_Click(object sender, EventArgs e) { Myobject obj = new Myobject(); obj.n1 = 1; obj.n2 = 2; obj.str = "sdfdsf"; IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, obj); stream.Close(); } [Serializable] public class Myobject { public int n1 = 0; public int n2 = 0; public String str = null; } private void button2_Click(object sender, EventArgs e) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read); Myobject obj = (Myobject)formatter.Deserialize(stream); stream.Close(); textBox1.Text = obj.str; }
无法找到程序集“client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [原]
2010-12-10 11:31:19| 分类: ASP.NET |字号 订阅问题场景: 有两个结构完全相同的类,一个写在client端,一个写在server端. 单独测试任何一个类都没有问题,但client端发送类的实例(对象)给server端时,server端在反序列化对象时提示:"无法找到程序集“client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”. 问题原因: 虽然client端和server端的这两个类的结构完全相同,但由于它们分别位于各自的namespace下,就导致了对象在反序列化时出现错误。解决办法: 写一个公用类库,把client端和server端都要用到的这个类写到此类库中,然后让client端和server端都引用这个公用类库(dll),这样位于同一个namespace下的类的实例在反序列化时就不会出错了.over!编辑器加载中... posted on 2011-10-28 13:31 阅读( ...) 评论( ...)