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

NuGet test for job file containing invalid JSON throws "Could not load file or assembly 'Microsoft.Build'" exception #11776

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rhyskoedijk
Copy link

@rhyskoedijk rhyskoedijk commented Mar 10, 2025

What are you trying to accomplish?

@brettfo, if the job file contains invalid JSON (e.g. see dependabot/cli#408), the NuGet updater will throw a "Could not load file or assembly 'Microsoft.Build'" exception instead of gracefully returning a JobErrorBase object.

updater | Unhandled exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
updater |
updater | File name: 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
updater |    at NuGetUpdater.Core.Run.ApiModel.JobErrorBase.ErrorFromException(Exception ex, String jobId, String currentDirectory)
updater |    at NuGetUpdater.Core.ExperimentsManager.FromJobFileAsync(String jobId, String jobFilePath) in /opt/nuget/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs:line 53
updater |    at NuGetUpdater.Cli.Commands.DiscoverCommand.<>c.<<GetCommand>b__5_0>d.MoveNext() in /opt/nuget/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs:line 31
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
updater |    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
updater | --- End of stack trace from previous location ---
updater |    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

image

This PR adds unit tests that reproduce the issue, but I don't know how to fix it as it seems that Microsoft.Build is already referenced in the project and it compiles without errors.

It looks like these tests pass in the CI pipeline, so maybe it is an environment issue. This issue can be reproduced if run from inside the dependabot-updater-nuget Docker image.

More context in tinglesoftware/dependabot-azure-devops#1548 (comment).

Do you have any suggestions?

Anything you want to highlight for special attention from reviewers?

How will you know you've accomplished your goal?

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Mar 10, 2025
@rhyskoedijk rhyskoedijk changed the title NuGet test for job file containing invalid JSON throws NuGet test for job file containing invalid JSON throws "Could not load file or assembly 'Microsoft.Build'" exception Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant