コンテンツにスキップ
Docs Try Aspire
Docs Try

Compiler Warning ASPIREEXPORT016

このコンテンツはまだ日本語訳がありません。

Version introduced: 13.4

DTO property '0' is a get-only mutable collection. Add an init accessor so System.Text.Json replaces the collection during DTO deserialization; otherwise collection values can be merged with initializer defaults.

This diagnostic warning is reported when an [AspireDto] type exposes a mutable collection property with only a getter. During DTO deserialization, System.Text.Json can populate the existing collection instead of replacing it. If the collection has initializer defaults, deserialized values can be merged with those defaults and produce unexpected DTO state.

The following code generates ASPIREEXPORT016:

C# — MyDto.cs
[AspireDto]
public class MyDto
{
public List<string> Items { get; } = new();
}

Add an init accessor so System.Text.Json can replace the mutable collection during deserialization:

C# — MyDto.cs
[AspireDto]
public class MyDto
{
public List<string> Items { get; init; } = new();
}

Suppress the warning with either of the following methods:

  • Set the severity of the rule in the .editorconfig file.

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIREEXPORT016.severity = none

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file:

    C# project file
    <PropertyGroup>
    <NoWarn>$(NoWarn);ASPIREEXPORT016</NoWarn>
    </PropertyGroup>