Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
QuestionBinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 4:01
mav.northwind8-Oct-08 4:01 
AnswerRe: BinaryFormatter: Serializing an object's base class Pin
PIEBALDconsult8-Oct-08 4:07
mvePIEBALDconsult8-Oct-08 4:07 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 4:12
mav.northwind8-Oct-08 4:12 
AnswerRe: BinaryFormatter: Serializing an object's base class Pin
#realJSOP8-Oct-08 4:17
mve#realJSOP8-Oct-08 4:17 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 4:31
mav.northwind8-Oct-08 4:31 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
#realJSOP8-Oct-08 4:46
mve#realJSOP8-Oct-08 4:46 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Dan Neely8-Oct-08 5:49
Dan Neely8-Oct-08 5:49 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 9:01
mav.northwind8-Oct-08 9:01 
Smile | :) Well, things tend do become simplified when stripping the context.

I have a system of several client applications and a server that are communicating via remoting. They all have a notion of Animal. Animal has a method public static void ToFile(Animal a, string file) (and the corresponding FromFile()).

For a new client, a Dog class had to be created, but since this class is only used with this client it doesn't make sense to put it into the library defining Animal.
Then the client wanted to serialize the Animal-part of one of the Dog objects using the static Animal.ToFile() method, but the binary formatter threw an exception because Dog wasn't marked as serializable.

The most intuitive method (for me) to solve this problem would be to find a way to tell the BinaryFormatter that what he gets really really is just an Animal, but I don't know how.
Other solutions would be to use aggregation instead of inheritance, but that would require some rewriting of existing code.
Or I could add a copy constuctor to Animal and actally create a new object, but that's not really the idea - I don't want to serialize a copy of a Dog, I only want to serialize the Animal-parts of the Dog...

Regards,
mav

--
Black holes are the places where God divided by 0...

AnswerRe: BinaryFormatter: Serializing an object's base class Pin
Ennis Ray Lynch, Jr.8-Oct-08 5:20
Ennis Ray Lynch, Jr.8-Oct-08 5:20 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 7:51
Mark Salsbery8-Oct-08 7:51 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Ennis Ray Lynch, Jr.8-Oct-08 8:45
Ennis Ray Lynch, Jr.8-Oct-08 8:45 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 9:21
Mark Salsbery8-Oct-08 9:21 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Ennis Ray Lynch, Jr.8-Oct-08 9:39
Ennis Ray Lynch, Jr.8-Oct-08 9:39 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 9:42
Mark Salsbery8-Oct-08 9:42 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 9:53
Mark Salsbery8-Oct-08 9:53 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Ennis Ray Lynch, Jr.8-Oct-08 10:03
Ennis Ray Lynch, Jr.8-Oct-08 10:03 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 10:34
Mark Salsbery8-Oct-08 10:34 
AnswerRe: BinaryFormatter: Serializing an object's base class Pin
Giorgi Dalakishvili8-Oct-08 7:35
mentorGiorgi Dalakishvili8-Oct-08 7:35 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 23:48
mav.northwind8-Oct-08 23:48 
AnswerRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 7:59
Mark Salsbery8-Oct-08 7:59 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 8:27
mav.northwind8-Oct-08 8:27 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 9:37
Mark Salsbery8-Oct-08 9:37 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
mav.northwind8-Oct-08 10:05
mav.northwind8-Oct-08 10:05 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 11:01
Mark Salsbery8-Oct-08 11:01 
GeneralRe: BinaryFormatter: Serializing an object's base class Pin
Mark Salsbery8-Oct-08 12:21
Mark Salsbery8-Oct-08 12:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.