Skip to content

CA5362 Solution example-code is invalid #55114

Description

@LukasGelke

Type of issue

Code does not work

Description

Example states:

[NonSerialized]
public ExampleClass ExampleProperty {get; set;}

however:
https://learn.microsoft.com/en-us/dotnet/api/system.nonserializedattribute?view=net-10.0

[System.AttributeUsage(System.AttributeTargets.Field, Inherited=false)]
public sealed class NonSerializedAttribute : Attribute

produces the following error:

CS0592: Attribute 'NonSerialized' is not valid on this declaration type. It is only valid on 'field' declarations.

please note that just changing the Atribute to [field: NonSerialized] does not "work", as it will raise the Analyzer CA5362 again

Page URL

https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5362

Content source URL

https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/quality-rules/ca5362.md

Document Version Independent Id

5bb21412-9df3-42bd-d423-62b2e12d93f7

Platform Id

8f5f157c-f4cf-76e7-438a-c2b74c5220c3

Article author

@LLLXXXCCC

Metadata

  • ID: 59c0feae-5e7a-9738-7f00-04bfda5c7752
  • PlatformId: 8f5f157c-f4cf-76e7-438a-c2b74c5220c3
  • Service: dotnet-fundamentals

Related Issues


Associated WorkItem - 601485

Metadata

Metadata

Assignees

Type

No type

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions