Arl*_*rlo 1 linker json.net webassembly uno-platform system.text.json
我一直在寻找 WASM 中发生的错误来解决此错误:
Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Hqub.MusicBrainz.API.Entities.Recording.
A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'recordings[0].id', line 1, position 86.
Run Code Online (Sandbox Code Playgroud)
我目前拥有的最好的线索是这篇关于 Xamarin for Android 使用的 Mono 运行时的旧博客文章: ,其中指出:
在项目属性的“Android 选项”选项卡中,有一个“链接器”选项卡。“链接”下拉列表中选定的选项是“仅限 Sdk 程序集”还是“Sdk 和用户程序集”?
如果是后者,则在链接时会跳过无参数构造函数,因为未检测到任何使用。因此将其更改为“Sdk Assemblies only”。
我尝试切换到 System.Text.Json,这会导致类似的错误:
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'Hqub.MusicBrainz.API.Entities.Recording'
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeCreateObjectDelegateIsNull (System.Type invalidType) <0x4b45408 + 0x0004e> in <filename unknown>:0
at System.Text.Json.JsonSerializer.HandleStartObject (System.Text.Json.JsonSerializerOptions options, System.Text.Json.ReadStack& state) <0x4b17ec0 + 0x001f6> in <filename unknown>:0
at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x4b16610 + 0x0017c> in <filename unknown>:0
at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonReaderState& readerState, System.Boolean isFinalBlock, System.ReadOnlySpan`1[T] buffer, System.Text.Json.JsonSerializerOptions options, System.Text.Json.ReadStack& readStack) <0x4b15610 + 0x00056> in <filename unknown>:0
at System.Text.Json.JsonSerializer.ReadAsync[TValue] (System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x4abbcc8 + 0x00356> in <filename unknown>:0
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () <0x4b71b40 + 0x00036> in <filename unknown>:0
at Hqub.MusicBrainz.API.MusicBrainzClient.GetAsync[T] (System.String url) <0x4924a28 + 0x006e0> in <filename unknown>:0
Run Code Online (Sandbox Code Playgroud)
我尝试在每个类中创建构造函数并将它们标记为internal,这似乎已将错误消息转移到不同的类型,但没有解决它。
任何帮助表示赞赏
是的,这是一个错误,表明删除未使用代码的链接器已经删除了构造函数,因为它不知道Json.NET(或System.Text.Json) 正在通过反射使用它。
没有与“仅 Sdk 程序集”选项完全相同的选项(因为本身没有“Wasm Sdk”),但您只需将包含该类型的程序集作为条目添加到RecordingWasmLinkerConfig.xml平台头文件夹的根目录中。
例如:
<assembly fullname="Hqub.MusicBrainz.API />
Run Code Online (Sandbox Code Playgroud)
(您可以在包含该类型的项目的“属性”选项卡中检查程序集名称。)
| 归档时间: |
|
| 查看次数: |
1033 次 |
| 最近记录: |