1

So I have a serialized binary file with some contents in it and I'm trying to deserialize it.

I have:

    try
    {
        using (Stream stream = File.Open(file, FileMode.Open))
        {
            BinaryFormatter bin = new BinaryFormatter();

            var contents = bin.Deserialize(stream);
        }
    }
    catch (IOException io)
    {
        Debug.LogError(io.ToString());
    }

But I get an IO Exception

System.IO.FileNotFoundException: Could not load file or assembly 'Packaging Tool, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'Packaging Tool, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

That's the start of the file itself. I tried it in a console application and it works perfectly, but when I import it into Unity3D, things get messy. Does someone know where the root of the problem may be?

Also, when I comment the line with bin.Deserialize, the exception disappears.

jimbo
  • 99
  • 1
  • 11

2 Answers2

0

It appears one or more of your assemblies could not be found at runtime. The error is likely due the file containing Packaging Tool missing or not being included in the output directory.

When you are importing to Unity3D, do you also import the dependencies? ie, the Packaging Tool file?

Kami
  • 19,134
  • 4
  • 51
  • 63
  • Thanks for your answer. And what is the best way to include the assembly? I mean, I don't want other people to see it. And is there a way to serialize/deserialize not depending on assembly? – jimbo Sep 18 '13 at 09:59
  • Before you start thinking about hiding it etc, you need to confirm if this resolves the issue. For testing to identify if this is the issue, import the library as you would others (or copy to the output folder where the resultant exe from the project is kept) - this will identify if this is the problem. – Kami Sep 18 '13 at 10:14
  • Well, I added the exe to the folder where the dll is and when I run it, the same exception is thrown... – jimbo Sep 18 '13 at 10:41
0

The Deserialize method converts the byte stream to objects, during serialization the Binary Formatter tries to locate an object apparently declared in assembly named Packaging Tool. Since the assembly can't be found, the object can't be instantiated and hence an exception is thrown.

Make sure the Packaging Tool assembly exists in your application folder or registered in GAC.