如何解决MissingMethodException Json.Serializer Constructor on type not found exception in WASM unoplatform
我正在使用 System.Text.Json.JsonSerializer.Deserialize
将字符串反序列化到我的类中。
这是我的课:
namespace Database
{
public class Song
{
public uint id { get; set; }
public string name { get; set; }
public string author { get; set; }
public int bpm { get; set; }
}
}
这里是反序列化的代码,jsonData 为 [{"id":1,"name":"1","author":"1","bpm":0},{"id":2,"name":"2","author":"2","bpm":0}]
List<Song> songs = JsonSerializer.Deserialize<List<Song>>(jsonData);
它在 Uno-Platform 中的 UWP 和 Android 项目上运行得非常好。但是,在 WASM 上抛出异常 MissingMethodException
。这是日志:
System.MissingMethodException: Constructor on type 'System.Text.Json.Serialization.Converters.listofTConverter`2[[System.Collections.Generic.List`1[[Database.song,BP.Wasm,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null]],mscorlib,Version=2.0.5.0,PublicKeyToken=7cec85d7bea7798e],[Database.song,PublicKeyToken=null]]' not found.
据我了解日志。它不知道如何反序列化 List<Song>
。 overview 或任何附加资源都没有说明在什么框架中反/序列化支持什么类型的一些例外情况。
我是否必须为 List
的 Song
和可能的其他集合定义我自己的转换器?这可能与 Uno 平台有关吗?还是我只是遗漏了一些微不足道的东西?
解决方法
这很可能是由于链接器剥离了所需的代码造成的。打开 WASM 项目中的 LinkerConfig.xml
文件并尝试在那里添加您的程序集/System.Text.Json
:
<assembly fullname="System.Text.Json" />
<assembly fullname="Database" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。