Skip to content
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

Add Try methods to JsonObject #111229

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Add Try methods to JsonObject #111229

wants to merge 4 commits into from

Conversation

Flu
Copy link

@Flu Flu commented Jan 9, 2025

As per the API proposed in #110244, the following functions have been added to JsonObject:

public bool TryAdd(string propertyName, JsonNode? value);
public bool TryAdd(string propertyName, JsonNode? value, out int index);
public bool TryGetPropertyValue(string propertyName, out JsonNode? jsonNode, out int index);

This resolves #110244

@Flu Flu marked this pull request as draft January 9, 2025 10:02
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 9, 2025
@Flu
Copy link
Author

Flu commented Jan 9, 2025

@dotnet-policy-service agree

@Flu
Copy link
Author

Flu commented Jan 9, 2025

@eiriktsarpalis Sorry to trouble you, I would have written some tests, but at the moment I seem not to be able to run any. I followed the testing guide here: docs/workflow/testing/libraries/testing.md

Neither dotnet build /t:Test nor running the test inside Visual Studio works, it complains about missing the SDK for .net 10. Not sure how to navigate this problem, since the guide says that if you build the clr and the libs with build.cmd -subset clr+libs -rc Release, then it should work. The build itself finishes succesfully, but trying to run the tests fails. Any idea why? Also, prior to trying to run dotnet build /t:Test, I did cd into runtime\src\libraries\System.Text.Json\tests.

@huoyaoyuan
Copy link
Member

it complains about missing the SDK for .net 10

Don't use the global dotnet command, but the dotnet.cmd at repository root instead. It will resolves to a local copy of nightly SDK.

@Flu
Copy link
Author

Flu commented Jan 9, 2025

@huoyaoyuan then how can I debug in Visual Studio if I need to use dotnet.cmd?

Also, for example, if I needed to execute the tests in ./src/libraries/System.Text.Json/tests/System.Text.Json.Tests/, how would I go about doing that? I tried doing .\dotnet.cmd build /t:Test /p:XUnitOptions="-class System.Text.Json.Tests.JsonNode.ParseTests" but it seems to be executing other tests that are not there, so not sure what the proper usage would be here.

@eiriktsarpalis
Copy link
Member

@Flu You can use the -vs flag in build.cmd to launch a solution using the bootstrapping sdk in the environment:

build.cmd -vs src\libraries\System.Text.Json\System.Text.Json.sln

That should make it possible to run tests from the test explorer as normal.

@Flu
Copy link
Author

Flu commented Jan 10, 2025

@eiriktsarpalis I am now getting this error when trying to run the tests from inside visual studio after I've used your command:

MSB4018: The "Microsoft.DotNet.ApiCompat.Task.ValidateAssembliesTask" task failed unexpectedly.
System.MissingMethodException: Method not found: 'System.ReadOnlySpan`1<!0> System.Collections.Immutable.ImmutableArray`1.AsSpan()'

This has nothing to do with my changes, as it's happening on the main branch as well, most recent commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a JsonObject.TryAdd method.
3 participants