且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从引用的 .NET Framework 项目序列化值类型期间 .NET Core 项目中的 TypeLoadException

更新时间:2021-10-26 06:14:37

这可能已在 .NET Core 3 中修复,但在此之前,可以使用以下解决方法:

This has presumably been fixed in .NET Core 3, but until then, the following workarounds are available:

  • 避免自动实现的属性;改用完整的属性或公共字段.(为了抑制编译器警告,我使用了 [SuppressMessage("", "IDE0032", Justification = "https://github.com/dotnet/core/issues/2981")] for这个目的.
  • 在同一个程序集或一些公共程序集中定义自定义System.Runtime.CompilerServices.IsReadOnlyAttribute.
  • Avoid auto-implemented properties; use full properties, or public fields instead. (In order to suppress the compiler warning, I used [SuppressMessage("", "IDE0032", Justification = "https://github.com/dotnet/core/issues/2981")] for this purpose.
  • Define a custom System.Runtime.CompilerServices.IsReadOnlyAttribute in the same assembly or some common assembly.

关于 Roslyn 问题的反馈