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

Exception when deserializing an interface #439

Closed
etki opened this issue Oct 12, 2019 · 1 comment
Closed

Exception when deserializing an interface #439

etki opened this issue Oct 12, 2019 · 1 comment
Labels

Comments

@etki
Copy link

etki commented Oct 12, 2019

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)
@aaubry aaubry added the bug label Oct 12, 2019
@aaubry
Copy link
Owner

aaubry commented Oct 12, 2019

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

@aaubry aaubry closed this as completed in 2c0ae4c Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants