Bug in framework/wcf/Basic/Contract/Data/NetDCSasDCSwithDCR/CS/DCSwithDCR/DCSwithDCR.cs
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 5.1k
- Avg merge
- 9h 11m
- Merged PRs (30d)
- 1
Description
**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.
```csharp
// 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
- [x] .NET Framework
- [ ] .NET Standard
Contributor guide
Assessment
This issue has not been assessed yet.