Monday, 26 August 2013

Type 'MyClass' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base...

Type 'MyClass' cannot inherit from a type that is not marked with
DataContractAttribute or SerializableAttribute. Consider marking the
base...

I get this error message when I try to serialize an entity which derives
from TableEntity:
Type 'MyClass' cannot inherit from a type that is not marked with
DataContractAttribute or SerializableAttribute. Consider marking the base
type 'Microsoft.WindowsAzure.Storage.Table.TableEntity' with
DataContractAttribute or SerializableAttribute, or removing them from the
derived type.
The error message is pretty clear about what's going wrong.
So my question is, how can I work around DataContractAttribute not being
decorated in the TableEntity class?
Code:
[DataContract]
public class MyClass : TableEntity
{
public string Name { get; set; }
public string Email { get; set; }
}
I need to serialize MyClass as a byte[] and save that into the table storage.
public class MyClassAsByteArray : TableEntity
{
public byte[] SomeByteArray { get; set; }
}
If anyone has a suggestion on how to serialize this as a byte[], please
let me know.

No comments:

Post a Comment