使用 .NET Standard 声明 C# 异常

Declare C# exception with .NET Standard

这个问题看起来太菜鸟了,但我无法在 15 分钟内google回答。

我正在尝试为 .net Standard 创建 class 库,但坚持使用异常定义。

我正在使用众所周知的 Exception 片段生成以下代码:

    [Serializable]
    public class MyException : Exception
    {
        public MyException() { }
        public MyException(string message) : base(message) { }
        public MyException(string message, Exception inner) : base(message, inner) { }
        protected MyException(
          SerializationInfo info,
          StreamingContext context) : base(info, context) { }
    }

但是,在编译过程中出现错误:

1>Exceptions\MyException.cs(2,22,2,35): error CS0234: The type or namespace name 'Serialization' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?)
1>Exceptions\MyException.cs(7,6,7,18): error CS0246: The type or namespace name 'SerializableAttribute' could not be found (are you missing a using directive or an assembly reference?)
1>Exceptions\MyException.cs(7,6,7,18): error CS0246: The type or namespace name 'Serializable' could not be found (are you missing a using directive or an assembly reference?)
1>Exceptions\MyException.cs(14,11,14,28): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
1>Exceptions\MyException.cs(15,11,15,27): error CS0246: The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?)

根据 this page dotnet 标准具有 SerializationAttribute。 我需要安装特定于目标 dotnet 标准 1.2 的东西吗?

SerializableAttributeincluded in .NET Standard 2.0,不是 1.2.