Skip to content

Collection expression with single element failed to serialize #133

Open
@Odonno

Description

@Odonno

I currently have an issue with a particular part of my code. Here is the exception:

   Did not expect any exception, but found System.ArgumentException: GenericArguments[0], '<>z__ReadOnlySingleElementList`1[My.Models.Model]', on 'Dahomey.Cbor.Serialization.Converters.CollectionConverter`2[TC,TI]' violates the constraint of type 'TC'.
 ---> System.TypeLoadException: GenericArguments[0], '<>z__ReadOnlySingleElementList`1[My.Models.Model]', on 'Dahomey.Cbor.Serialization.Converters.CollectionConverter`2[TC,TI]' violates the constraint of type parameter 'TC'.

You can reproduce by serializing a single element array created via the new Collection expression feature, see:

var array = [42];

I use an array of complex of objects but I suppose it should have the same effect on primitives.
Note that standard arrays like new [] { 42 } still work perfectly.

I did not take a closer look but I suppose it has to do with the underlying (optimized?) type generated by the Collection expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions