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

Mismatched behavior for verify the KnownType with Desktop version #17889

Closed
huanwu opened this issue Jul 19, 2016 · 0 comments · Fixed by dotnet/corefx#10598
Closed

Mismatched behavior for verify the KnownType with Desktop version #17889

huanwu opened this issue Jul 19, 2016 · 0 comments · Fixed by dotnet/corefx#10598
Assignees
Milestone

Comments

@huanwu
Copy link
Contributor

huanwu commented Jul 19, 2016

When serialize a object with unknown type, if the serializer contains a DataContractResolver, it will end up with SerializationException. However, no exception thrown from Desktop Version. This is because, in core version, it always verify knowtype if there's resolver. In the code:
System.Private.DataContractSerialization\src\System\Runtime\Serialization\XmlObjectSerializerWriteContext.cs

Core Version, which always return true when there's resolver :

protected virtual bool WriteTypeInfo(XmlWriterDelegator writer, DataContract contract, DataContract declaredContract)
{
    if (XmlObjectSerializer.IsContractDeclared(contract, declaredContract))
    {
        return false;
    }
    bool hasResolver = DataContractResolver != null;
    if (hasResolver)
    {
        WriteResolvedTypeInfo(writer, contract.UnderlyingType, declaredContract.UnderlyingType);
    }
    else
    {
        WriteTypeInfo(writer, contract.Name, contract.Namespace);
    }
    return hasResolver;
}

Desktop Version, which always return false.

protected virtual bool WriteTypeInfo(XmlWriterDelegator writer, DataContract contract, DataContract declaredContract)
    {
        if (!XmlObjectSerializer.IsContractDeclared(contract, declaredContract))
        {
            if (DataContractResolver == null)
            {
                WriteTypeInfo(writer, contract.Name, contract.Namespace);
                return true;
            }
            else
            {
                WriteResolvedTypeInfo(writer, contract.OriginalUnderlyingType, declaredContract.OriginalUnderlyingType);
                return false;
            }
        }
        return false;
    }
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants