Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Scenario:
I have a class which contains the following:

C#
[Serializable]
public class Model
{
     public string Name { get; set; }
     public List<Camera> Cameras { get; set; }
     public int DefaultCamera { get; set; }

     public bool IsDefaultLightON { get; set; }
     public List<Light> Lights { get; set; }
     
     public Model3DGroup Models { get; set; }
     public ModelType ModelType { get; set; }
     
     public Model() { }
}


Problem:
I have applied Serializable but i get an error that Model3DGroup is not marked as serializable.

[Error: "Type 'System.Windows.Media.Media3D.Model3DGroup' in Assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."]

Want to achieve:
Convert class to stream

Question:
Is there any solution to do this through serialization?
Is there any alternative solution to convert my "Model" class to stream?
Posted
Updated 5-Jun-13 0:26am
v2

1 solution

You will have to handle the (de)serialization of Model3DGroup yourself.

Create a [Serializable]-decorated class that derives from Model3DGroup and implements the ISerializable interface[^]. If all goes well, you should be able to replace the original Model3DGroup by your SerializableModel3DGroup wherever it occurs without changing any of the surrounding code. Plus Model would be serializable.

The difficult or tedius part will then be the interface implementation, which basically means the GetObjectData(SerializationInfo, StreamingContext) method and a constructor with the same parameters. The former turns your object into a byte stream, the latter reverts the process. More precisely, you will have to make it behave like that. But how you're achieving this totally depends on the Model3DGroup class and what you want to serialize out of it (basically all information that is needed to reconstruct an instance thereof).
 
Share this answer
 
Comments
le.Festin 6-Jun-13 14:01pm    
i think that is a brilliant answer to my question. I will look into it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900