2017-05-18 5 views
2

この質問は新人に見えますが、私は15分以内にGoogleの回答をすることができませんでした。.NET標準でC#例外を宣言する

.net標準のクラスライブラリを作成しようとしていて、例外定義が張り付いています。コンパイル時に、私はエラーを取得しています、しかし

[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に固有のものをインストールする必要がありますか?

+0

ファイルの先頭に正しい「using」ステートメントがありますか? – Maarten

+0

using System; System.Serializable属性のために十分である必要があります – st78

答えて

6

SerializableAttributeは、included in .NET Standard 2.0であり、1.2ではない。

+0

ここで私は1つを得ることができますか? 私はVS 2017がデフォルトでインストールしていないことに驚いています – st78

+0

私はそれがまだリリースされていないことを確認しました: https://github.com/dotnet/standard/issues/219 – st78

関連する問題