简体   繁体   中英

Deserialization exception : Unable to find assembly

I work on winforms project.

I try to deserialize an object:

private void CreateObjects()
        {
            try
            {
                using (FileStream fs = new FileStream("path to file", FileMode.Open))              
                   sObjects = (Objects)(new BinaryFormatter().Deserialize(fs)); 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

But in this row:

sObjects = (Objects)(new BinaryFormatter().Deserialize(fs)); 

I get this exception:

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

Any idea what may cause this exception?

If your class con taint object that do not have the Serializeable tag, you can't Deserialize them. You will need to mark these object with the NonSerializable tag.

http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx

If in your AssemblyInfo.cs version defined like this:

[assembly: AssemblyVersion("1.0.*.*")]
[assembly: AssemblyFileVersion("1.0.*.*")]

Then change it to this:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM