Bug in framework/wcf/Basic/Contract/Data/NetDCSasDCSwithDCR/CS/DCSwithDCR/DCSwithDCR.cs

未关闭
#6,467 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
csharp
领域
backend

调研方向

从 framework/wcf/Basic/Contract/Data/NetDCSasDCSwithDCR/CS/DCSwithDCR/DCSwithDCR.cs 开始,并结合字典字段检查 MyDataContractResolver.TryResolveType()。更新示例,使其使用预期的字典而不发生局部遮蔽,然后验证 .NET Framework 示例能够构建,并且 resolver 的行为仍然正确。

由索引模型根据 Issue 内容生成。

描述

Local variable dictionary or field dictionary?

In the MyDataContractResolver class in https://github.com/dotnet/samples/blob/main/framework/wcf/Basic/Contract/Data/NetDCSasDCSwithDCR/CS/DCSwithDCR/DCSwithDCR.cs, there is a field dictionary and there is also a local variable dictionary in the method TryResolveType(). So the field dictionary is never used. It seems to me that the original intent was to use the field dictionary and the local variable dictionary shouldn't have been there.

    // DataContractResolver to be used by the DataContractSerializer
    class MyDataContractResolver : DataContractResolver
    {
        private XmlDictionary dictionary = new XmlDictionary();    <-- Here **********

        ...

        // Used at serialization
        // Maps any Type to a new xsi:type representation
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
            {
                XmlDictionary dictionary = new XmlDictionary();    <-- And here **********
                typeName = dictionary.Add(type.FullName);
                typeNamespace = dictionary.Add(type.Assembly.FullName);
            }
            return true;
        }
    }

Note that the same code is also on this page - https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/datacontractserializer-datacontractresolver-netdatacontractserializer.

Target framework

Check the .NET target framework(s) being used, and include the version number(s).

  • .NET Core
  • .NET Framework
  • .NET Standard
主要语言
C#
星标
3.7k
派生
5.1k
平均合并
19 小时 47 分钟
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/samples 的其他 Issue

查看 dotnet/samples 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。