Skip to content

The CodeDomSerializer does not properly deserialize a CodeTypeReference to a generic type #14259

@aerworker

Description

@aerworker

Root cause

PR9099

.NET version

8.0.23

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

7.0.20

Issue description

The CodeDomSerializerBase.GetTypeNameFromCodeTypeReference method returns an incorrect type name for the generic type, e.g. for the nullable int type it returns [[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] instead of System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]. The subsequent call to the manager.GetType method fails to resolve the string to a type.

Steps to reproduce

Run the following code:

class Program {
    static void Main(string[] args) {
        var serializer = new CodeDomSerializer();
        var expr = new CodeTypeOfExpression(new CodeTypeReference(typeof(long?)));
        var manager = new Manager();
        var result = serializer.Deserialize(manager, expr);
    }
}
class Manager : IDesignerSerializationManager {
    //...
    public object GetService(Type serviceType) {
        if(serviceType == typeof(System.ComponentModel.Design.TypeDescriptionProviderService))
            return null;
        throw new NotImplementedException();
    }

    public Type GetType(string typeName) {
        if(typeName == "System.Int64")
            return typeof(long);
        string expectedTypeName = $"System.Nullable`1[[{typeof(long).AssemblyQualifiedName}]]";
        if(typeName != expectedTypeName)
            throw new Exception("Type name is incorrect");
        else
            return typeof(long?);
    }
    //...
}

Metadata

Metadata

Labels

needs-area-labeluntriagedThe team needs to look at this issue in the next triage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions