Я хочу десериализовать граф объектов в моем клиенте Blazor, когда он возвращается из метода API сервера Blazor (аналогично примеру Weatherforecasts).Мне нужно использовать мой собственный метод десериализации с пользовательскими конвертерами, основанными на JsonConverter, потому что мой граф объектов имеет составные объекты, которые реализуют тот же интерфейс.
Все работает за пределами моего проекта блазора, и если я возвращаю граф объекта какстрока для клиента была правильно сериализована.Это десериализация, которая не работает.
blazor.webassembly.js:1 WASM: System.MissingMethodException: Constructor on type 'System.ComponentModel.ReferenceConverter' not found.
blazor.webassembly.js:1 WASM: at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) <0x20812e8 + 0x0032c> in <f4072889680a4c139ae7f58d7e8832a7>:0
blazor.webassembly.js:1 WASM: at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) <0x2080d18 + 0x000c8> in <f4072889680a4c139ae7f58d7e8832a7>:0
blazor.webassembly.js:1 WASM: at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture) <0x267adf8 + 0x00016> in <f4072889680a4c139ae7f58d7e8832a7>:0
blazor.webassembly.js:1 WASM: at System.SecurityUtils.SecureCreateInstance (System.Type type, System.Object[] args, System.Boolean allowNonPublic) <0x267ad28 + 0x00092> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.SecurityUtils.SecureCreateInstance (System.Type type) <0x2678c10 + 0x00008> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.ReflectTypeDescriptionProvider.CreateInstance (System.Type objectType, System.Type callingType) <0x2677f58 + 0x00034> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.ReflectTypeDescriptionProvider.SearchIntrinsicTable (System.Collections.Hashtable table, System.Type callingType) <0x26774e8 + 0x002e8> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.ReflectTypeDescriptionProvider+ReflectedTypeData.GetConverter (System.Object instance) <0x266a3b8 + 0x00180> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.ReflectTypeDescriptionProvider.GetConverter (System.Type type, System.Object instance) <0x2669d30 + 0x00016> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.TypeDescriptor+TypeDescriptionNode+DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetConverter () <0x2669a88 + 0x0003e> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) <0x2665718 + 0x00010> in <19bbec7b522743e889bff711c7b96bc3>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonTypeReflector.CanTypeDescriptorConvertString (System.Type type, System.ComponentModel.TypeConverter& typeConverter) <0x265a220 + 0x0000a> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.DefaultContractResolver.CanConvertToString (System.Type type) <0x265a010 + 0x0000a> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) <0x260ec98 + 0x0013c> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver.ResolveContract (System.Type type) <0x260e2b8 + 0x000a2> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe (System.Type type) <0x260dda0 + 0x00034> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) <0x27f8df0 + 0x000c8> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) <0x27eac60 + 0x001ac> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bce40 + 0x000d0> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) <0x27cd020 + 0x00270> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor`1[T] creator, System.String id) <0x27d4980 + 0x00142> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) <0x27c0418 + 0x0006a> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bdb80 + 0x002c2> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bce40 + 0x000b0> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) <0x27f8df0 + 0x0034e> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) <0x27eac60 + 0x001ac> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bce40 + 0x000d0> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) <0x27cd020 + 0x00270> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor`1[T] creator, System.String id) <0x27d4980 + 0x00142> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) <0x27c0418 + 0x0006a> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bdb80 + 0x002c2> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) <0x27bce40 + 0x000b0> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) <0x260daa8 + 0x001b0> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) <0x25f1928 + 0x000ac> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) <0x25f1258 + 0x00010> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) <0x25f84e8 + 0x00076> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) <0x25f7c70 + 0x0000c> in <12891e825fce44a581e5bbbb579c1d49>:0
blazor.webassembly.js:1 WASM: at Localization.Jliff.Graph.Converter.Deserialize (System.String json) [0x0006f] in E:\Dev\DotNet\JliffEditor\JliffEditor.Jliff\Serialization\Converter.cs:76
blazor.webassembly.js:1 WASM: at JliffEditor.Client.Pages.Editor.OnInitAsync () [0x00096] in E:\Dev\DotNet\JliffEditor\JliffEditor.Client\Pages\Editor.razor:46
blazor.webassembly.js:1 WASM: at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x206d928 + 0x00160> in <13ab8f8dacb6489b93c9655168c56037>:0
blazor.webassembly.js:1 WASM: at Microsoft.AspNetCore.Components.Rendering.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x224efa0 + 0x000fe> in <13ab8f8dacb6489b93c9655168c56037>:0
Буду признателен за любые предложения о том, как подойти к решению этой проблемы.
РЕДАКТИРОВАТЬ
Думая, что я мог бы переключить сериализаторы Json, я перешел по ссылкам через сообщение: Объявление .NET Core 3.0 Preview 5 на System.Text.Json Docs , что указывает на то, что полиморфное поведение не являетсяподдерживается.В поисках других альтернатив, возможно, TinyJSON ...
EDIT II
TinyJSON работает до определенной степени.При передаче данные включают в себя дополнительные @type
свойства, которые стираются с моей стороны, но эй.Оставьте вопрос без ответа в случае простого решения использовать Newtonsoft.