Skip to content

Exception when deserializing an interface #439

Closed
@etki

Description

@etki

YamlDotNet tries to get generic reflection on an interface that is not guaranteed to be generic:

    public sealed class DefaultObjectFactory : IObjectFactory
        //...
        public object Create(Type type)
        {
            if (type.IsInterface())
            {
                if (defaultInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out var implementationType))
                {
                    type = implementationType.MakeGenericType(type.GetGenericArguments());
                }
            }

if (defaultInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out var implementationType))

Trace:

System.InvalidOperationException: This operation is only valid on generic types.
   at System.RuntimeType.GetGenericTypeDefinition()
   at YamlDotNet.Serialization.ObjectFactories.DefaultObjectFactory.Create(Type type)
   at YamlDotNet.Serialization.NodeDeserializers.ObjectNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)

Activity

aaubry

aaubry commented on Oct 12, 2019

@aaubry
Owner

You're right. I should fix that. Thanks for reporting!

added a commit that references this issue on Jul 17, 2024
2c0ae4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aaubry@etki

        Issue actions

          Exception when deserializing an interface · Issue #439 · aaubry/YamlDotNet