Hi,
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:
The server includes the level editor, which would create the maps. Maps is an Arraylist with each map, which includes an int32 for X/Y location, as well as a custom class for each square on the map. On connecting, the client messages the server the bytelength of the Maps.dat file, if the server says it's valid, it loads the Maps.dat file through a function that essentially is Maps = MapLoader.LoadM aps(); which is the same as the servers. The server saves it just like most basic serialization functions:
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.
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:
Code:
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;
}
}
}
Code:
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.
Comment