-
Notifications
You must be signed in to change notification settings - Fork 360
NullReferenceException when mapping from multiple sources when one source is null #414
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
Comments
At first glance, this looks like a bug. I will attempt to reproduce this with a regression test and see if I can pinpoint the problem. Is it possible for you to post a stack trace, or relevant parts of a stack trace? Can you also confirm that you are using the latest version of Mapster? |
I confirm this issue is occurring using the Mapster 7.3.0 Nuget package. The behaviour when using a tuple with a single element matches my expectations. For instance:
but when using multiple elements it throws an exception (even without a config specified)
I'm not sure what should happen if no config is specified, but certainly in my use-case I was expecting dest.Application to be null if src.Item3 is null |
Yes! I have same problem with version 7.3.0 `config.ForType<(Pair?, Record?, Favorite?), PairDto>()
|
A class as a reference type can always have a Null value. It seems to be related to how nullability is determined for reference Tuple and ValueType members (a, b, c) it is ValueTuple and Item3 has NullableAttribute [Nullable((byte) 1)] == not-null; when you use reference Tuple Which gave a false negative when checked in InvokerModel.
|
I have 3 source items to map to a destination. There is a possibility the third item will be null.
I create a config as follows:
My expectation was that a null value for Item3 should be handled and a null value returned for the Application property of the output.
When I run the mapping:
var result = (x, y, z)Adapt<Output>(config.Config);
when z is null, then a NullReferenceException is thrown.
Is this a bug?
The text was updated successfully, but these errors were encountered: