Skip to content

False positive RS1035 error for Environment.NewLine #6467

@bitbonk

Description

@bitbonk

Analyzer

Diagnostic ID: RS1035 The symbol '{0}' is banned for use by analyzers: Analyzers should not read their settings directly from environment variables

Analyzer source

Unknown, I am using SDK 6.0.405 and the following Nuget packages

Microsoft.CodeAnalysis.CSharp 4.3.0
Microsoft.CodeAnalysis.Analyzers 3.3.4
Microsoft.CodeAnalysis.Workspaces.Common 4.3.0

Describe the bug

When I use Environment.NewLine inside a source generator, I get the error

Error RS1035 : The symbol 'Environment' is banned for use by analyzers: Analyzers should not read their settings directly from environment variables.

I understand that it maybe be dangerous to read settings from environment variables but the class Environment has members that AFAIK have nothing to do with environment variables and therefore should be save to use.

In the case of Environment.NewLine, what is the right way add a newline dynamically in generated code?

Steps To Reproduce

  1. Create a source generator using the SDK and nuget pakages mentioned above
  2. Use Environment.NewLine anywhere in the generator,
  3. See error

Expected behavior

No error occurs when I use Environment.NewLine

Actual behavior

The error

Error RS1035 : The symbol 'Environment' is banned for use by analyzers: Analyzers should not read their settings directly from environment variables

occurs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions