Skip to content

Attempt to fix browser-wasm test failures. - #87680

Merged
eiriktsarpalis merged 2 commits into
dotnet:mainfrom
eiriktsarpalis:fix-mono-test-failures
Jun 16, 2023
Merged

eiriktsarpalis merged 2 commits into
dotnet:mainfrom
eiriktsarpalis:fix-mono-test-failures

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

Attempts to fix the browser-wasm test failures that #87637 introduced. cc @stephentoub

@ghost

ghost commented Jun 16, 2023

Copy link
Copy Markdown

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

Issue Details

Attempts to fix the browser-wasm test failures that #87637 introduced. cc @stephentoub

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json

Milestone: -

{
// browser-wasm compat -- ensure the linker doesn't trim away constructor parameter names from KVP.
Type[] genericArguments = typeToConvert.GetGenericArguments();
Type keyValuePairType = typeof(KeyValuePair<,>).MakeGenericType(genericArguments);

@eiriktsarpalis eiriktsarpalis Jun 16, 2023 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@eerhardt the code in line 51 is redundant, but it's there to have the linker not trim away the constructor parameter names of KeyValuePair. Do you know of any incantations that might let us avoid it in this case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe if you put a [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(KeyValuePair<,>)] on this method, the trimmer will see that you are going to access the constructor through reflection and not trim away the parameter names.

cc @vitek-karas

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, we are doing that already to get tests to work in Blazor:

[Fact]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties, typeof(Tuple<,,,,,,,>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties, typeof(Tuple<,,,,,,>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties, typeof(Tuple<>))]
public async Task TupleDeserialization_MoreThanSevenItems()

I'd be inclined to just put that annotation in the relevant tests rather than arbitrarily doing it for KVP in product code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be inclined to just put that annotation in the relevant tests rather than arbitrarily doing it for KVP in product code.

Agreed, especially since this code is marked "RequiresUnreferencedCode". That is the stance we've taken elsewhere in STJ w.r.t. trimming and our "unsafe" APIs. For example - #53317

@eiriktsarpalis

Copy link
Copy Markdown
Member Author

Can confirm that the blazor-wasm legs are green with this change, merging to unblock CI.

@eiriktsarpalis
eiriktsarpalis merged commit 76da696 into dotnet:main Jun 16, 2023
@eiriktsarpalis
eiriktsarpalis deleted the fix-mono-test-failures branch June 16, 2023 12:50
eiriktsarpalis added a commit to eiriktsarpalis/runtime that referenced this pull request Jun 16, 2023
eiriktsarpalis added a commit that referenced this pull request Jun 16, 2023
* Address feedback from #87680.

* Update src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/JsonSerializerWrapper.Reflection.cs

Co-authored-by: Eric Erhardt <[email protected]>

---------

Co-authored-by: Eric Erhardt <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Jul 16, 2023
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.

3 participants