Tabriz Atayi
Tabriz Atayi

Reputation: 6120

Exception in Deserialize process

I wrote a dll which has several classes. One of them is called DataDesign.

[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; 
    }

When I use this dll in my application I have a problem in deserilizing process. Serilizing ends up with successesful. But in deserialization I have an EXCEPTION.

The Exception is

"Unable to find assembly 'AnalyzingData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."

AnalyzingData is name of 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);
                    }
}

//this datadesign class

How I can solve this problem?

MS visual Studio2010 . Windows 7 Thank you for your attention!

Upvotes: 0

Views: 94

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1063068

BinaryFormatter serializes the concrete objects in a graph. Even if you expose something as IField, BinaryFormatter is only looking at the actual SomeTypeOfField : IField instances. This means that to deserialize this data you need the assemblies that were in use when you serialized the data. It sounds like when you serialized, it was getting some types (in the graph) from the AnalyzingData assembly. This means that to deserialize this data, you are going to need this assembly again.

There are some complicated ways of working around this with Binder, but in most cases I would advise choosing a serializer that maps to your scenario: if you want to deserialize without the same original types / assemblies, then you should use a contract-based serializer.

Alternatively, just find AnalyzingData.dll, and add a reference to it so that it gets deployed with your application (set the copy-local to true, too).

Upvotes: 1

Justin Harvey
Justin Harvey

Reputation: 14672

Whatever process is deserializing needs to have access to your AnalyzingData Dll, i.e. it needs to be in the bin folder of that app or other place that it can load it from.

Upvotes: 2

Related Questions