Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] System.Reflection.AmbiguousMatchException: Ambiguous match found #2308

Open
okarpov opened this issue Apr 11, 2023 · 3 comments
Open
Labels

Comments

@okarpov
Copy link

okarpov commented Apr 11, 2023

Version
5.0.16

Describe the bug
Using this version and 5.0.15 leads to System.Reflection.AmbiguousMatchException: Ambiguous match found
after some time of usage

Code to Reproduce
its simple - just make a simple multithread code to generate and insert/update typed objects inside of a collection
we use the following class:

public class Cookie
    {
        public long Id { get; set; }
        public string Guid { get; set; }
        public long Long { get; set; }
        public CookieCollection cookieCollection { get; set; }
    }

Expected behavior
should not be any issue

Screenshots/Stacktrace
at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name, BindingFlags bindingAttr)
at LiteDB.BsonMapper.DeserializeList(Type type, BsonArray value)
at LiteDB.BsonMapper.Deserialize(Type type, BsonValue value)
at LiteDB.BsonMapper.DeserializeObject(EntityMapper entity, Object obj, BsonDocument value)
at LiteDB.BsonMapper.Deserialize(Type type, BsonValue value)
at LiteDB.LiteQueryable1.<ToEnumerable>b__27_2(BsonDocument x) at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)
at LiteDB.LiteCollection`1.FindById(BsonValue id)

Additional context

@okarpov okarpov added the bug label Apr 11, 2023
@okarpov okarpov changed the title [BUG] Using string Guid as Id leads to System.Reflection.AmbiguousMatchException: Ambiguous match found after some time [BUG] Using string Guid as Id leads to System.Reflection.AmbiguousMatchException: Ambiguous match found Apr 11, 2023
@okarpov okarpov changed the title [BUG] Using string Guid as Id leads to System.Reflection.AmbiguousMatchException: Ambiguous match found [BUG] System.Reflection.AmbiguousMatchException: Ambiguous match found Apr 11, 2023
@okarpov
Copy link
Author

okarpov commented Apr 11, 2023

removing public CookieCollection cookieCollection { get; set; } property seems solving the issue
but then there is another issue - can not add same _id value

@Luigi6821
Copy link
Contributor

Luigi6821 commented Jun 14, 2023

Hi, I found same issue when deserializing list.
The bug is in line 260 of file BsonMapper.Deserialize.cs.
The affected line is the following:
var addMethod = type.GetMethod("Add");
Which could cause problem when type contains more than one Add method but deserialize needs only the one having
as argument itemType.
So if you do the following:
var addMethod = type.GetMethod("Add", new Type[] { itemType });
it solves the issue.

Please let me know if the bug fix can be released soon.
Thanks in advance.
PS: I created a pull request for it #2332
Regards
Luigi

@mbdavid
Copy link
Collaborator

mbdavid commented Jun 14, 2023

Thanks for your PR @Luigi6821!! I will review to add some tests about this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants