2 개의 특성을 가진 클래스가 있습니다. 하나의 속성은 HttpResponseMessage이며이를 직렬화해야합니다. 나는 HttpResponse를 통해 클래스와 [DataMember]에 대해 [DataContract]를 만들었다.HttpResponseMessage serialization
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.
잘못된 것입니다 : 나는이 오류가 다음을 테스트 할 때
[DataContract]
public class ResponseItem
{
[DataMember]
public HttpResponseMessage ResponseMessage { get; set; }
[DataMember]
public CacheInfoItem CacheInfo { get; set; }
}
문제는 다음과 같습니다 클래스입니까?
편집 : 나는 저장 방법이 있습니다
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();
}
}
를하지만 시리얼 라이저가 직렬화하기 위해 클래스의 상단에 [Serialize]
를 추가 HttpResponseMessage에게
왜이 유형은 직렬화 될 수 있다는 생각? 무엇을 성취하려고합니까? –
나는 그것이 직렬화 될 수 있는지 정말로 모른다. 응답 메시지를 저장하고 싶습니다. – newone
메시지를 꺼내서 메시지를 직렬화하십시오. 게으르지 말고 모든 것을 직렬화하려고 시도하십시오. –