JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C#


CSHARP.CLASS.SER.OCNON : Nonserializable Outer Class (C#)

要旨

An inner non-static serializable class has a non-serializable outer class.

Serialization allows one to dump an object into a file and recover (deserialize) it later. For this to work, C# requires the class of the object to implement the System.Runtime.Serialization.ISerializable interface. Moreover, all instance non-transient fields of the class must be serializable themselves. For inner non-static classes, also the outer class must be serializable. In order to distinguish dumps of objects for distinct versions of the same class, it is required that serializable classes define a static field containing the serial version of the class.

プロパティ

クラス名 Nonserializable Outer Class (C#)
日本語クラス名 Nonserializable Outer Class (C#)
クラス分類 信頼性 (reliability)
ニーモニック CSHARP.CLASS.SER.OCNON
カテゴリー
CWE CWE:913 Improper Control of Dynamically-Managed Code Resources
対応言語 C# で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Nonserializable Outer Class (C#)"

using System.Runtime.Serialization;
namespace DocumentationExamples
{
    public class Serialization : ISerializable
    {
        public static void Main(string[] args)
        { }

        private readonly object f;         // Nonserializable Field (C#) warning issued here 
        private readonly SerializationC.Inner inner;

        public Serialization(object f)
        {
            this.f = f;
            inner = new SerializationC.Inner();
        }
        public void GetObjectData(SerializationInfo info, StreamingContext context) { }
    }
    public class SerializationC
    {
        public class Inner : ISerializable  // Nonserializable Outer Class (C#) warning issued here 
        {
            public void GetObjectData(SerializationInfo info, StreamingContext context) { }
        }
    }
    
}

解決法

Guarantee that all instance non-transient fields of a serializable class are themselves serializable. Make inner serializable classes have a serializable outer class, or make them static.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.