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

[QUESTION] Why can't I use IReadOnlyList<T>? #1626

Closed
RMariowski opened this issue Apr 12, 2020 · 1 comment
Closed

[QUESTION] Why can't I use IReadOnlyList<T>? #1626

RMariowski opened this issue Apr 12, 2020 · 1 comment
Labels

Comments

@RMariowski
Copy link

RMariowski commented Apr 12, 2020

Hi, I'm new to LiteDB and I have a question about this chunk of code: https://pastebin.com/SCkQkYzz

Why I need to use writable list type (IList/List) in Point A (line 14) to avoid

LiteDB.LiteException: 'Failed to create instance for type 'System.Collections.Generic.IReadOnlyList1[[ConsoleApp.CustomerOrder, ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' from assembly 'System.Collections.Generic.IReadOnlyList1[[ConsoleApp.CustomerOrder, ConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Checks if the class has a public constructor with no parameters.'

that occurs in Point B (line 60)?

If it's trying to add CustomerOrder to list from Customer, then this behaviour is highly unwanted... especially for me :). If yes, then how to avoid that?

@lbnascimento
Copy link
Contributor

@xandev Previously, our mapper only knew how to serialize properties of an interface type if the type was exactly IList, ICollection, IEnumerable, ISet or IDictionary. I fixed it and now it should work for any interface type that implements IEnumerable. This fix will be present in the next incremental release.

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