English 中文(简体)
航天问题
原标题:Serialization problem

I have created a phonebook application and it works fine after a awhile i liked to make an upgrade for my application and i started from scratch i didn t inherit it from my old class,and i successes too ,my request "I want to migrate my contacts from the old application to the new one" ,so i made an adapter class for this reason in my new application with the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace PhoneBook
{
    class Adapter
    {
        PhoneRecord PhRecord;   //the new application object
        CTeleRecord TelRecord; //the old application object
        string fileName;

    public Adapter(string filename)
    {
        fileName = filename;
    }

    public void convert()
    {

        PhRecord = new PhoneRecord(); 
        TelRecord = new CTeleRecord();

        FileStream OpFileSt = new FileStream(fileName, FileMode.Open,FileAccess.Read);


        BinaryFormatter readBin = new BinaryFormatter();



        for (; ; )
        {
            try
            {
                TelRecord.ResetTheObject();

                TelRecord = (CTeleRecord)readBin.Deserialize(OpFileSt);

                PhRecord.SetName = TelRecord.GetName;
                PhRecord.SetHomeNumber = TelRecord.GetHomeNumber;
                PhRecord.SetMobileNumber = TelRecord.GetMobileNumber;
                PhRecord.SetWorkNumber = TelRecord.GetWorkNumber;
                PhRecord.SetSpecialNumber = TelRecord.GetSpecialNumber;
                PhRecord.SetEmail = TelRecord.GetEmail;
                PhRecord.SetNotes = TelRecord.GetNotes;
                PhBookContainer.phBookItems.Add(PhRecord);


            }
            catch (IOException xxx)
            {
                MessageBox.Show(xxx.Message);


            }
            catch (ArgumentException tt)
            {
                MessageBox.Show(tt.Message);
            }
            //if end of file is reached
            catch (SerializationException x)
            {
                MessageBox.Show(x.Message + x.Source);
                break;
            }

        }
        OpFileSt.Close();

        PhBookContainer.Save(@"d:MyPhBook.pbf");

         }

    }
}

the problem is when i try to read the file ctreated by my old application i receive serialization exception with this message "Unalel to find assembly PhoneBook,Version=1.0.0.0,Culture=neutral,PublicK eyToken=null"

而例外的起因是调和。

当我阅读了与我的旧申请相同的档案(Which是档案的起源)时,我没有问题,也不知道做些什么来使我的适应者的工作。

问题回答

When the class is serialised, it includes the assembly information of the class. It does this so the deserializer knows what type of class to create with the serialised data.

问题在于,虽然这两类人似乎相同,但并非因为他们在不同的集会上。

建议采取的方式是,总是在一间图书馆开设可系列的课程。 然后,在您的V2.0号申请中,你可以提及V1.0号大会,然后你可以将物体erial灭。

如果您的V1.0级班在一间图书馆(例如,在可起诉的图书馆中重新设置),你可以在一间教室里开设V2.0级课程,并增加您的V1.0级功能,将班级改为V2.0级。

提出你们可能提出的任何问题,作为评论。

希望这一帮助。

宾泰语对集会改变并不宽容。 很久以前,我就得出结论,运输是K(关于)而不是任何种类的储存——它就是,太平了:

简言之,我将使用另一个序列器,但以合同为基础,而不是以类型为依据(因此,任何具有相同特性的类型都可以分享数据):

其中只有<代码>DataContractSerializer>,,目前支持“图表”模式(而不是树木)。

如果你有重新战斗的现有数据,我会非常希望利用旧的法典(或与其非常接近的)以合同形式重报数据。 虽然你说你只是制造了它,但也许这是一个问题。

如前所述,档案中载有贵阶层完全合格的组合名称,这在你的新项目中发生了变化。 如果您的组别、职称和国名相等,你可以把大会的形式简单地放在形式上:

BinaryFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;

当格式试图装上这种类型的时,使用LadWith PartialName。 See DNMS for more info.

也可以写一个,用于解决分歧。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签