dotnet/runtime

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

开放

#45,207 创建于 2020年11月25日

 (3 条评论) (0 个反应) (0 位负责人)C# (5,445 个派生)batch import
area-Serializationhelp wanted

仓库指标

星标
 (17,886 个星标)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

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.

贡献者指南