I'm attempting to write objects to azure blobs for persistent storage and for some reason 1 property is never serialized and i'm unsure why.
This is the object
[Serializable]
public class BlobMetaData
{
public DateTimeOffset? ModifiedDate { get; set; }
public string ContentType { get; set; }
public string Name { get; set; }
// size of the file in bytes
public long Length { get; set; }
}
this is the function that saves the data to Azure storage.
public void Save(string filename,BlobProperties blobProperties)
{
//full path to the blob
string saveFile = _clientDirectory + filename;
CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(saveFile);
//blobMetaData properly gets all the right values.
BlobMetaData blobMetaData = ConvertBlobProperties(blobProperties,filename);
// I convert it to a stream
MemoryStream stream = SerializeToStream(blobMetaData);
blockBlob.UploadFromStream(stream);
}
Here is how I serialize the data.
private MemoryStream SerializeToStream(BlobMetaData blobMetaData)
{
XmlSerializer serializer = new XmlSerializer(typeof(BlobMetaData));
MemoryStream stream = new MemoryStream();
serializer.Serialize(XmlWriter.Create(stream), blobMetaData);
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
for some reason.. all values are properly stored in Azure XML except the ModifiedDate.. it is always blank even though before I call SerializeToStream() I check blobMetaData and it does have the value.. so its getting lost during the serialization process.
Here is what the XML looks like
<?xml version="1.0" encoding="utf-8"?><BlobMetaData
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"><ModifiedDate /><ContentType>application/octet-stream</ContentType><Name>u_ex14060716.log</Name><Length>652</Length></BlobMetaData>
as you can see modifiedDate is empty. Anyone have any idea why?