Skip to main content

K1001

Message properties must be read-only.

All messages must be immutable. See Message for more information. Remove the setter from all properties or set the setter to private.

Noncompliant Code Example

The following example has a getter and setter.

public class SomeRequest
{
    // This property has beth get and set defined.
    public string Name { get; set;  }
}

Compliant Examples

The following example uses a get only property.

public class SomeRequest
{
    // Initialization moved to constructor which is required for serialization.
    public SomeRequest(string name)
    {
        this.Name = name;
    }

    // Property has getter only.
    public string Name { get; }
}

The following example has a private set.

public class SomeRequest
{
    // Initialization moved to constructor which is required for serialization.
    public SomeRequest(string name)
    {
        this.Name = name;
    }

    // Property has a private set.  Some frameworks require there to be a setter.
    public string Name { get; private set; }
}

Exceptions

None