【问题标题】:Deserialization requires a parameterless constructor反序列化需要一个无参数的构造函数
【发布时间】:2020-07-20 15:18:47
【问题描述】:

在 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
  }

}

有什么线索吗?有解决方案或解决方法吗?或者我可以关注的问题?

问候, 迈克尔

【问题讨论】:

    标签: uno-platform webassembly


    【解决方案1】:

    这通常是由链接器配置问题引起的。

    如果您要反序列化的类位于不直接位于 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>
    

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 2011-05-06
      • 2013-02-19
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2021-01-11
      相关资源
      最近更新 更多