Skip to content

Conversation

@buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Aug 10, 2022

Fix Missing.Value corner-case behavior changes in .NET 7

In .NET 6 and below all arguments were copied back

// copy out. This should be made only if ByRef are present.
// n.b. cannot use Span<T>.CopyTo, as parameters.GetType() might not actually be typeof(object[])
for (int index = 0; index < arguments.Length; index++)
parameters![index] = arguments[index];

Later in .NET 7 it seems updated to copy only if ByRef are present as mentioned in the comment, this is causing a regression when Missing.Value is provides as argument and default value used to written back instead of Missing.Value

Fixes #73106

@ghost
Copy link

ghost commented Aug 10, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix Missing.Value corner-case behavior changes in .NET 7

In .NET 6 and below all arguments were copied back

// copy out. This should be made only if ByRef are present.
// n.b. cannot use Span<T>.CopyTo, as parameters.GetType() might not actually be typeof(object[])
for (int index = 0; index < arguments.Length; index++)
parameters![index] = arguments[index];

Later in .NET 7 it seems updated to copy only if ByRef are present as mentioned in the comment, this is causing a regression when Missing.Value is provides as argument and default value used to written back instead of Missing.Value

Fixes #73106

Author: buyaa-n
Assignees: -
Labels:

area-System.Reflection

Milestone: -

@buyaa-n buyaa-n requested a review from jkotas August 10, 2022 23:09
}

arg = paramInfo.DefaultValue;
parameters[i] = arg = paramInfo.DefaultValue;
Copy link
Member

@jkotas jkotas Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to do the parameters[i] assignment only once in all cases, ie do it in the fast path and in the slow path right before the CheckValue check.

BTW: The value of the fast path for default values is questionable. Reading of the default value is slow, and so we gaining very little from this fast path. You can also just delete the fast path here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for "fast path" was actually required since the "slow path" did not re-check this and would have failed in Debug build due to an Assert.

The later refactor commit changed the order and now the "fast path" can occur naturally after the Type.Missing fix-ups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he check for "fast path" was actually required since the "slow path" did not re-check this and would have failed in Debug build due to an Assert.

The assert in the slow path is broken. It should be removed. It is what #73103 is about.

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Aug 12, 2022

The failure looks infra related, merging

@buyaa-n buyaa-n merged commit f52d8c5 into dotnet:main Aug 12, 2022
@buyaa-n buyaa-n deleted the copy-missing-value branch August 12, 2022 02:39
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing.Value corner-case behavior changes in .NET 7

3 participants