I was wondering how I would go about deserializing a file that was serialized from a different project. I've tried a couple things, but I can't really seem to figure it out. When looking it up, it seemed like it would be solved by just including a class project that did the actual serializing and deserializing, but when I tried this, I still couldn't get it to work. I created a DLL that was referenced by both of my projects, the server and the client, and the DLL does both the Serialization and Deserialization, and returns the value through a function:
Expand|Select|Wrap|Line Numbers
- public ArrayList LoadMaps() {
- try {
- bOp.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
- if(File.Exists(MapPath)) {
- fin = File.OpenRead(MapPath);
- MapLoad = (ArrayList)bOp.Deserialize(fin);
- fin.Close();
- }
- return MapLoad;
- } catch(Exception Ex) {
- Console.WriteLine(Ex.Message);
- return null;
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- public void SaveMaps(ArrayList MapArray) {
- fout = File.Create(MapPath);
- bOp.Serialize(fout, MapArray);
- fout.Close();
- }
The result is the error:
Unable to find assembly 'MultiWinsock Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
From what I understand, the error resulting is due to the assembly information of the writing client and the reading client being different, causing the deserialization to fail, but I'm not exactly sure how I would go about solving this. I've tried a few different methods, such as just having each project load the function itself, having the DLL do it (as above), and putting all the project (Server, Client, DLL) in the same solution, but I couldn't figure out an answer. I'm still quite new to C# as you can probably tell, and so I'm not sure on how to go about this. Note that the server can save and load the maps it creates without any problems at all.
Any help would be appreciated.