Skip to main content
Source: AL0001ProhibitPrimaryConstructorParameterReassignmentAnalyzer.cs

Description

Primary constructor parameters should not be reassigned as this can lead to confusion and bugs.

Bad Code

public class Service(ILogger logger)
{
    public void Reset() => logger = null;
}

Good Code

public class Service(ILogger logger)
{
    private readonly ILogger _logger = logger;
}

Properties

  • Category: Design
  • Severity: Error
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0001.severity = warning