J'ai une classe avec 2 attributs. Un attribut est un HttpResponseMessage et je dois le sérialiser. J'ai fait un [DataContract] sur la classe et un [DataMember] sur HttpResponse. Voici la classe:HttpResponseMessage sérialisation
[DataContract]
public class ResponseItem
{
[DataMember]
public HttpResponseMessage ResponseMessage { get; set; }
[DataMember]
public CacheInfoItem CacheInfo { get; set; }
}
le problème est quand je teste alors je reçois cette erreur:
An exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred
in mscorlib.dll but was not handled in user code
Additional information: Type 'System.Net.Http.StreamContent' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking all of its
members you want serialized with the DataMemberAttribute attribute. If the type is a
collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft
.NET Framework documentation for other supported types.
ce qui est faux?
EDIT: J'ai une méthode de sauvegarde:
public static async Task SaveObjectAsync(Object toBeSaved, string fileName = null,
StorageLocation storageLocation = StorageLocation.Local, SerializerType serializerType =
SerializerType.DataContractJson)
{
Type type = toBeSaved.GetType();
fileName = getFileName(fileName, type, serializerType);
StorageFolder folder = getStorageFolder(storageLocation);
MemoryStream memoryStream = new MemoryStream();
Serializer serializer = getSerializer(serializerType, type);
serializer.WriteObject(memoryStream, toBeSaved);
StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (Stream fileStream = await file.OpenStreamForWriteAsync())
{
memoryStream.Seek(0, SeekOrigin.Begin);
await memoryStream.CopyToAsync(fileStream);
await fileStream.FlushAsync();
}
}
, mais il semble que le sérialiseur ne peut pas gérer la HttpResponseMessage
Pourquoi pensez-vous que ce type peut être publié en feuilleton? Qu'est-ce que vous essayez d'accomplir? –
Je ne sais pas vraiment si elle peut être sérialisée. Je veux enregistrer le responsemessage – newone
Alors sortez le message, puis sérialiser le message. Ne soyez pas paresseux et essayez de sérialiser le tout. –