反序列化需要一个无参数的构造函数
Deserialization requires a parameterless constructor
我在 WASM (#uno-platform) 中使用 .Net Standard 2.0 Nuget 时遇到问题(同样的问题直接链接项目):
反序列化需要无参数构造函数(Microsoft 和 Newtonsoft 反序列化器)。
显然,所涉及的 类 具有无参数构造函数,并且 Nuget 在 UWP、WPF 和 Xamarin 项目中运行良好:
public class MCEFile
{
public List<Form> Forms { get; set; }
public List<Item> Items { get; set; }
[JsonConstructor]
public MCEFile()
{
Forms = new List<Form>();
Items = new List<Item>();
}
}
public class Item
{
public long ID { get; set; }
...
// - - - - - -
[JsonConstructor]
public Item()
{
// dummy for WASM
}
}
有线索吗?有解决方案或解决方法吗?或者我可以关注的问题?
此致,
迈克尔
这通常是由链接器配置问题引起的。
如果您要反序列化的 class 位于不直接位于 WebAssembly 头项目中的程序集或项目中,则需要在 LinkerConfig.xml
文件中包含程序集名称。
例如:
<linker>
<assembly fullname="MyProject.Wasm" />
<assembly fullname="MyOtherLibrary" />
<assembly fullname="System.Core">
<!-- This is required by Json.NET and any expression.Compile caller -->
<type fullname="System.Linq.Expressions*" />
</assembly>
</linker>
我在 WASM (#uno-platform) 中使用 .Net Standard 2.0 Nuget 时遇到问题(同样的问题直接链接项目):
反序列化需要无参数构造函数(Microsoft 和 Newtonsoft 反序列化器)。
显然,所涉及的 类 具有无参数构造函数,并且 Nuget 在 UWP、WPF 和 Xamarin 项目中运行良好:
public class MCEFile
{
public List<Form> Forms { get; set; }
public List<Item> Items { get; set; }
[JsonConstructor]
public MCEFile()
{
Forms = new List<Form>();
Items = new List<Item>();
}
}
public class Item
{
public long ID { get; set; }
...
// - - - - - -
[JsonConstructor]
public Item()
{
// dummy for WASM
}
}
有线索吗?有解决方案或解决方法吗?或者我可以关注的问题?
此致, 迈克尔
这通常是由链接器配置问题引起的。
如果您要反序列化的 class 位于不直接位于 WebAssembly 头项目中的程序集或项目中,则需要在 LinkerConfig.xml
文件中包含程序集名称。
例如:
<linker>
<assembly fullname="MyProject.Wasm" />
<assembly fullname="MyOtherLibrary" />
<assembly fullname="System.Core">
<!-- This is required by Json.NET and any expression.Compile caller -->
<type fullname="System.Linq.Expressions*" />
</assembly>
</linker>