   [.net] Trouble with VertexBuffer and XML Serialization
  Hi ,So i was workin on a game in c# and i had a struct   public struct Terrain    {  public CustomVertex.PositionTextured[] vertices;  public int[] indices;  public Microsoft.DirectX.Direct3D.VertexBuffer vertexBuffer;  public Microsoft.DirectX.Direct3D.IndexBuffer ib;  public int[,] heights;   }then later in the program the user can choose to save   serializer = new System.Xml.Serialization.XmlSerializer(typeOf(Terrain));  But i get the error There was an error reflecting type 'Engine_V1._1.MainPage.Terrain'.Please help!   
  Try putting a SerializableAttribute on your type and a NonSerializedAttribute on your vertex and index buffer.   ;  So does that mean i cannot save my vertexbuffer to a file?   ;Quote:Original post by harminalSo does that mean i cannot save my vertexbuffer to a file?Not directly. What you want is to save the data inside the vertex buffer to a file, not the vertex buffer itself. In this case, it is likely that you'll have to write an amount of custom serialization logic to get/set the data from the vertex buffer while serializing/deserializing.   ;  Crud!I also thought is there anyway i could convert the vertex buffer into binary?   ;  The problem is that vertex buffers are typically a representation or proxy to memory on your graphics device.  It has been a long time since I looked at managed DX, but if I recall correctly there were some flags you could set during buffer creation -- or something similar -- that could make it readable.   ;  You can't serialize the vertex buffer object directly. You need to serialize the data in that buffer. You can gain access to this data by locking the buffer. Alternatively you could serialize with the data you have that initially populates the terrain meshes, if your buffers are being created such that they are not lockable. This is probably more desirable anyhow.   ;Quote:I also thought is there anyway i could convert the vertex buffer into binary?I suggest having a look at the DirectX ID3DXMesh (Mesh in MDX, I think), which wraps buffers (apart from other information). With the related save/load functionality maybe this is what you are looking for: You can have arbitrary vertex formats, and handle text, binary and even a compressed serialization. I don't know if you can actually add custom data like your height-field, though. Consider using a texture for the latter anyway.You either have to implement a proper serialization on your own or find a way to convert your format to and from such a Mesh. Hope that helps.   