dotnet/runtime

C# compiler should not report CS0649 when the fields in question are marked with [DataMember] attribute

Open

#45.207 aberto em 25 de nov. de 2020

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)C# (5.445 forks)batch import
area-Serializationhelp wanted

Métricas do repositório

Stars
 (17.886 stars)
Métricas de merge de PR
 (Mesclagem média 12d 11h) (661 fundiu PRs em 30d)

Description

Version Used:

Visual studio 2019 16.8.2

Steps to Reproduce:

Compile code like this:

[DataContract]
sealed class TimeSeriesPoint
{
	[DataMember]
	public float compliance, volume;
}

Expected Behavior:

Maybe no warnings at all.

Maybe a different message, like "...will always have its default value 0, unless set by deserializing".

Actual Behavior:

Warning CS0649: Field 'TimeSeriesPoint.volume' is never assigned to, and will always have its default value 0.

This is incorrect because despite these fields are never assigned to, they won't always have a default value, due to serialization.

Guia do colaborador