I am using DataContractSerializer and DataContractResolver to substitute the functionality of NetDataContractSerializer because I am porting my framework library to .Net standard 2.0 and gives me an error for not able to resolve the special character like `, <,> for the TypeName and TypeNamespace. for other tags the special characters are replaces with their respective Entity references.
I am following this to implement my Resolveryour text
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractresolver?view=netstandard-2.0
// Used at deserialization
// Allows users to map xsi:type name to any Type
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
XmlDictionaryString tName;
XmlDictionaryString tNamespace;
if (dictionary.TryGetValue(typeName, out tName) && dictionary.TryGetValue(typeNamespace, out tNamespace))
{
return this.assembly.GetType(tNamespace.Value + "." + tName.Value);
}
else
{
return null;
}
}
// 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)
{
string name = type.Name;
string namesp = type.Namespace;
typeName = new XmlDictionaryString(XmlDictionary.Empty, name, 0);
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, namesp, 0);
if (!dictionary.ContainsKey(type.Name))
{
dictionary.Add(name, typeName);
}
if (!dictionary.ContainsKey(type.Namespace))
{
dictionary.Add(namesp, typeNamespace);
}
return true;
}
I don't understand why special characters in TypeName are replaces with their respective Entity references. Any help would be appreciated.