[.net] deserialize

Started by
3 comments, last by Goober King 15 years, 10 months ago
Ok I went off and got stuck again. So I recently asked for some direction on how to save an object to disk for later use, which led me to serialize /deserialize. After writing the saver and secondary loading application, it is looking like I may need to store the objects in a dll since I am reading and writing in two independently compiled programs(is this accurate?). Now here's the(a) dumb question I can't seem to answer. How does one import a dll file created with C# ? The DllImport examples I've used and found don't really fit the class structure. Do I even need to do that? Are there rules on how I should lay out such a dll? I'm definitely missing some key info on something that may qualify as basic, but I need some guidance all the same.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
Advertisement
Yes, in order to deserialize the objects the program will have to know where to find the information about the types.

DllImport is only for working with native DLL's. If you write a DLL in C#, you don't need to use it. All you need to do is add a reference to it in your application. Right click the references folder in the solution explorer, click Add Reference, the browse tab, and find the dll from your library project with the types in it. Or, if the dll project is part of the same solution, just select it from the Projects tab in the Add Reference dialog.
I wondered about that. I guess I should have been able to figure that one out though. Anyway I'll give it a go tonight. thank you.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
If you need to do it at runtime, not at compile time, then have a look at System.Reflection.Assembly.LoadFile, and other Assembly methods.
I have one more bit I would like clarification on. If I serialize a set of objects does it need to go in its own file? Currently I embed the data in a file along with other information, but I'm getting thrown an error saying

Quote:
Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.


I'm currently using objects defined from the same dll in both programs.

edit
wait it looks like I'm off a byte on my read for some reason. Got it kinda working using a separate file for now.

[Edited by - Goober King on June 19, 2008 10:55:25 PM]
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork

This topic is closed to new replies.

Advertisement