Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
chadsugithub opened this issue Dec 8, 2023 · 0 comments
Open
1 of 3 tasks

Comments

@chadsugithub
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant