Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

donnie-msft
Copy link
Contributor

@donnie-msft donnie-msft commented Oct 3, 2025

Bug

Fixes: NuGet/Home#14579

Description

Moves the Utf8Json helper classes into NuGet Shared.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 10, 2025
@donnie-msft donnie-msft changed the title [Draft] Move Utf8JsonStreamReader & extensions to NuGet Shared Move Utf8JsonStreamReader & extensions to NuGet Shared Oct 13, 2025
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 13, 2025
@donnie-msft donnie-msft marked this pull request as ready for review October 13, 2025 21:17
@donnie-msft donnie-msft requested a review from a team as a code owner October 13, 2025 21:17
NuGet.sln Outdated Show resolved Hide resolved
}

internal bool ReadNextTokenAsBoolOrThrowAnException(byte[] propertyName)
internal bool ReadNextTokenAsBoolOrThrowAnException(byte[] propertyName, string invalidAttributeString)
Copy link
Contributor

@kartheekp-ms kartheekp-ms Oct 13, 2025

Choose a reason for hiding this comment

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

I know that you are simply moving the file to NuGet Shared in this PR, but out of curiosity, I am wondering why this method only throws an error when reading the boolean value from the JSON object and the other methods don't. When I checked the callers of this method, they are not handling the exception as a special case. That makes me think: do we really need this method? Can we simply call the ReadNextTokenAsBoolOrFalse method instead and delete this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good point. I see that it was discussed in the PR introducing it and the decision was to rename it to be distinct from ReadNextTokenAsBoolOrFalse.
I agree it's unclear why this is important, but there are 2 tests explicitly checking for an exception. Therefore, this could be a behavior change which I don't want to take on in this refactoring. See:

public async Task GetPackageSpec_WithInvalidSdkAnalysisLevel_ThrowsAnException()
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
// Arrange
using var testDirectory = TestDirectory.Create();
var projectBuildProperties = new Mock<IVsProjectBuildProperties>();
projectBuildProperties.Setup(b => b.GetPropertyValue(ProjectBuildProperties.SdkAnalysisLevel))
.Returns("9.ainvlaid");
var projectAdapter = CreateProjectAdapter(testDirectory, projectBuildProperties);
Mock<IVsProjectAdapter> projectAdapterMock = Mock.Get(projectAdapter);
var projectServices = new TestProjectSystemServices();
var testProject = new LegacyPackageReferenceProject(
projectAdapter,
Guid.NewGuid().ToString(),
projectServices,
_threadingService);
var settings = NullSettings.Instance;
var testDependencyGraphCacheContext = new DependencyGraphCacheContext(NullLogger.Instance, settings);
// Act & Assert
await Assert.ThrowsAsync<ArgumentException>(async () => await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext));
}
[Fact]
public async Task GetPackageSpec_WithInvalidUsingMicrosoftNetSdk_ThrowsAnException()
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
// Arrange
using var testDirectory = TestDirectory.Create();
var projectBuildProperties = new Mock<IVsProjectBuildProperties>();
projectBuildProperties.Setup(b => b.GetPropertyValue(ProjectBuildProperties.UsingMicrosoftNETSdk))
.Returns("falsetrue");
var projectAdapter = CreateProjectAdapter(testDirectory, projectBuildProperties);
Mock<IVsProjectAdapter> projectAdapterMock = Mock.Get(projectAdapter);
var projectServices = new TestProjectSystemServices();
var testProject = new LegacyPackageReferenceProject(
projectAdapter,
Guid.NewGuid().ToString(),
projectServices,
_threadingService);
var settings = NullSettings.Instance;
var testDependencyGraphCacheContext = new DependencyGraphCacheContext(NullLogger.Instance, settings);
// Act & Assert
await Assert.ThrowsAsync<ArgumentException>(async () => await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext));
}

@donnie-msft donnie-msft force-pushed the dev-donnie-msft-pjRefactorHelperAll branch from c453148 to 0edef0c Compare October 14, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Utf8JsonStreamReader.cs to build\Shared

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.