0

我写了一个有几个类的dll。其中之一称为数据设计。

[Serilizible]
public class DataDesign
    {
        [NonSerialized]
        HorizantalFields _horizantalFields;
        [NonSerialized]
        VerticalFields _verticalFields;
        [NonSerialized]
        GeneralDataDesignViewType _dataDesignView;
        [NonSerialized]
        Dictionary<FieldTemplateType, string> _templateTable;
        [NonSerialized]
        public List<string> ProcessedData;

        List<IField> _fields; 
    }

当我在我的应用程序中使用这个 dll 时,我在反序列化过程中遇到了问题。序列化以成功告终。但是在反序列化中我有一个例外。

例外是

“无法找到程序集 'AnalyzingData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'。”

AnalyzingData 是 dll 的名称。

DeSerilizeClass()
{
                    BinaryFormatter bin = new BinaryFormatter();
                    dataDesign=new DataDesign();

                    DataDesign dd= (DataDesign)bin.Deserialize(stream);
}

Serilize()
{
                    using (FileStream sr = new FileStream(String.Format(@"{0}\{1}", Parameters.SavedConfigurationsDirectory, dataDesignName),FileMode.CreateNew, FileAccess.Write))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        bin.Serialize(sr, this);
                    }
}

//这个数据设计类

我该如何解决这个问题?

微软视觉工作室2010。Windows 7 感谢您的关注!

4

2 回答 2

2

反序列化的任何进程都需要访问您的 AnalyzingData Dll,即它需要位于该应用程序的 bin 文件夹中或可以从中加载它的其他位置。

于 2012-10-08T07:46:10.713 回答
1

BinaryFormatter序列化图中的具体对象。即使您将某些内容公开为IField,BinaryFormatter也只是查看实际SomeTypeOfField : IField实例。这意味着要反序列化此数据,您需要序列化数据时正在使用的程序集。听起来当您序列化时,它从AnalyzingData程序集中获取了一些类型(在图中)。这意味着要反序列化此数据,您将再次需要此程序集。

有一些复杂的方法Binder可以使用 .

或者,只需 findAnalyzingData.dll并添加对它的引用,以便它与您的应用程序一起部署(也将 copy-local 设置为 true)。

于 2012-10-08T07:46:23.853 回答