-
Notifications
You must be signed in to change notification settings - Fork 334
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
PreserveReference and "An item with the same key has already been added." ArgumentException #102
Comments
Hi, I tried to reproduce, but it works fine. Could you pls provide reproducible code?
|
thanks on your response, config.NewConfig<ISomeEntity, SomeViewModel>()
.ConstructUsing(entity => container.Resolve<SomeViewModel.Factory>()(entity))
.IgnoreAttribute(typeof(DoNotMapAttribute))
.IgnoreNullValues(true)
.PreserveReference(true); ...but I should know better, I'll provide an example. |
I have no clue why PreserveReference doesn't work in your case. Mapster checks item not exists before adding new item to dictionary. My guess is there might be some other issues that cause the problem. |
And just to update, I didn't have enough time but I figured out where the problem is, roughly, I have hierarchical data structure and I was applying |
Hi, even I don't know root cause of this problem. I changed from Dictionary.Add to Dictionary[key] when adding new references to solve this issue. If you can provide test case, I'm happy to inspect the problem. I will close this issue for now. |
I'm having an issue with
PreserveReference
, I worked around it and I pretty much stopped using it, but I'd like to know if I'm missing something (which is likely).so, when I have circular references
PreserveReference
didn't resolve that for meand when I have (what seems as, it's hard to trace it, I didn't debug it with Mapster source, will do if needed) 2 properties pointing to the same object reference - then I get the above error (which is a typical dictionary/hash issue somewhere inside the Mapster code).
so it's simple hierarchy that I'm trying to map (basically entities to view-models, pretty typical), no circular references (I made sure of that, the code is quite mature)
what it's supposed to actually handle (2 properties pointing to the same object) is when it fails (that error)
as soon as I remove the PreserveReference all is working (just not preserved references of course)
I'll try and dive deeper into this, provide a sample solution etc.,
but I just wanted to see if this is a known issue, or even if you ever encountered it, or it's something specific to my data/code.
The text was updated successfully, but these errors were encountered: