XmlSerializer _serializer = new XmlSerializer(typeof(SuggestResponse));
валится вот в такую ошибку
System.InvalidOperationException : There was an error reflecting type 'Dadata.Model.SuggestResponse`1[Dadata.Model.Party]'.
----> System.InvalidOperationException : Cannot serialize member 'Dadata.Model.SuggestResponse`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]].suggestions' of type 'System.Collections.Generic.IList`1[[Dadata.Model.Suggestion`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]], Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]]', see inner exception for more details.
----> System.NotSupportedException : Cannot serialize member Dadata.Model.SuggestResponse`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]].suggestions of type System.Collections.Generic.IList`1[[Dadata.Model.Suggestion`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]], Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at Elecsnet.EntityStorage.Agents.DaDataAgent.FindPartyAsync() in D:\Repository\Elecsnet.EntityStorage\Elecsnet.EntityStorage.Agents\DaDataAgent.cs:line 43
at Elecsnet.Spark.Tests.DaDataAgentsTests.TestMethodSuccessTest() in D:\Repository\Elecsnet.EntityStorage\Elecsnet.EntityStorage.Tests\DaDataAgentsTests.cs:line 36
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.b__0()
at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--InvalidOperationException
at System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type)
at System.Xml.Serialization.StructModel.GetFieldModel(FieldInfo fieldInfo)
at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
using System.Text;
using System.Text.Json;
using System.Xml.Serialization;
using Dadata;
using Dadata.Model;
using Microsoft.Extensions.Logging;
агента конструирую вот так
DaDataClient = new SuggestClientAsync(ApiToken, webServiceHost);
метод для вызова вот такой и четыре попытки сериализации
public async Task FindPartyAsync()
{
var result = await DaDataClient.FindParty("7707083893");
string json = JsonSerializer.Serialize(result);
MemoryStream jsonMemoryStream = new MemoryStream();
await JsonSerializer.SerializeAsync(jsonMemoryStream, result);
json= Encoding.UTF8.GetString(jsonMemoryStream.GetBuffer());
XmlSerializer _serializer = new XmlSerializer(typeof(SuggestResponse));
using (var stream2= new MemoryStream())
{
_serializer.Serialize(stream2, result);
stream2.Position = 0;
json= Encoding.UTF8.GetString(stream2.GetBuffer());
}
return json;
}
при выводе в json сериализуется в пустую строку
а на строке
XmlSerializer _serializer = new XmlSerializer(typeof(SuggestResponse));
валится вот в такую ошибку
System.InvalidOperationException : There was an error reflecting type 'Dadata.Model.SuggestResponse`1[Dadata.Model.Party]'.
----> System.InvalidOperationException : Cannot serialize member 'Dadata.Model.SuggestResponse`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]].suggestions' of type 'System.Collections.Generic.IList`1[[Dadata.Model.Suggestion`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]], Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]]', see inner exception for more details.
----> System.NotSupportedException : Cannot serialize member Dadata.Model.SuggestResponse`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]].suggestions of type System.Collections.Generic.IList`1[[Dadata.Model.Suggestion`1[[Dadata.Model.Party, Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]], Dadata, Version=23.6.1.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at Elecsnet.EntityStorage.Agents.DaDataAgent.FindPartyAsync() in D:\Repository\Elecsnet.EntityStorage\Elecsnet.EntityStorage.Agents\DaDataAgent.cs:line 43
at Elecsnet.Spark.Tests.DaDataAgentsTests.TestMethodSuccessTest() in D:\Repository\Elecsnet.EntityStorage\Elecsnet.EntityStorage.Tests\DaDataAgentsTests.cs:line 36
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.b__0()
at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--InvalidOperationException
at System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type)
at System.Xml.Serialization.StructModel.GetFieldModel(FieldInfo fieldInfo)
at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
--NotSupportedException