locked
SerializationException thrown when deserializing: "Unable to find assembly" RRS feed

  • Question

  • hi all ^^ 

    that is my problem: i got an application with 2 forms, each having a button, save and open respectevely. the one with the save button serializes an object on a file, the one with open deserializes it. In thi process, i'm using OpenFileDialog e SaveFileDialog Forms. I am able to serialize the file correctely, but during the deserialization i got an exception thrown: "Unable to find assembly..."

    here's the serialization code: 
    [code]
                    //Crea l'oggetto ResultsToSerialize 
                    MyObj resultsToSerialize;
                    // istanzio l'oggetto

                    IFormatter binaryFormatter = new BinaryFormatter();
                    Stream fileStream = new FileStream (saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.None);
                    binaryFormatter.Serialize(fileStream, resultsToSerialize);

                    fileStream.Close();
    [/code]

    and here the deserialization one:
    [code] 
                    MyObj resultsToSerialize;
                    IFormatter binaryFormatter = new BinaryFormatter();

                    Stream fileStream = new FileStream (openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.None);
                    MessageBox.Show("filestream creato");
                    try
                    {
                        resultsToSerialize = (MyObj)(binaryFormatter.Deserialize(fileStream));
                    }
                    catch (SerializationException se)
                    {
                        MessageBox.Show("SE: " + se.Message);
                    }
                    finally
                    {
                        fileStream.Close();
                    }
    [/code] 

    I tried to find an answer googling a bit, but there isn't a clear answer at all. Someone says it's a .NET framework v1.5 issue (but i'm using the 3.5), somene that the binaryFormatter object inserts an unique string (??) in each serialized file, and thus it's impossible to deserialize an object in a class that's not the one that has serialized it. I've also heard that the "unable to find the assembly" error when deserializing was due to the fact I was trying to serialize/deserialize in two different application (but i got two different forms in the same application).

    any ideas? thank you all ;)

    Thursday, December 18, 2008 11:19 PM

Answers

All replies

  • i got some news: as someone suggested be, i used the  Assembly Binding Log Viewer (Fuslogvw.exe) to find where my error is. I found out it's about an assembly association, here's the interesting log part about the error (i'm just hand-translating it, if i manage to change language to the viewer i can post the whole log)


    REG: the same association has been formerly detected. Error hr = 0x80070002.
    ERR: critical error during the pre-download verify (hr = 0x80070002).

    As far as I know, the last two rows are the detailed error message of my runtime SerializationException. I cannot understand what "the same association has been formerly detected" could mean, since i'm just deserializing a file, not taking care of assembly associations at all.
    Friday, December 19, 2008 7:20 AM
  •  after *alot* of googling i found a solution. I found out it was a bug of .NET Framework that's still unfixed in v3.5 (source: http://beta.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=119402)


    here's a workaround suggested by a user (just a few lines of code): http://www.eggheadcafe.com/software/aspnet/33503762/deserialize-causes-except.aspx

    • Marked as answer by edhickey Monday, December 22, 2008 8:13 PM
    Friday, December 19, 2008 9:39 PM