Skip to content

Fail Builds Fast When SDKResolvers Throw Exceptions - #6763

Merged
rainersigwald merged 11 commits into
dotnet:mainfrom
benvillalobos:resolvers-failfast
Sep 1, 2021
Merged

rainersigwald merged 11 commits into
dotnet:mainfrom
benvillalobos:resolvers-failfast

Conversation

@benvillalobos

@benvillalobos benvillalobos commented Aug 17, 2021 •

Copy link
Copy Markdown
Member

Fixes #6762

Context

When SDK Resolvers fail, we currently log a warning and try to continue the build. This leads to a failure at some point in the future, which is confusing for customers.

Changes Made

  • SdkResolverService now catches exceptions and throws an SdkResolverException
  • Evaluator catches SdkResolverException and fails the build, providing the inner-error message along with MSB4242.
  • MSB4243 freed up. See notes below

Testing

Tested on a local standalone sdk. See comments below.

Notes

  • MSB4242 now has a slightly different meaning. It's a catch-all "sdk resolvers failed somehow" exception. It will then report whatever the resolver's message was, so the resolver's error codes had to had to be removed. Removing the other error codes prevents this sort of message: MSB4242: Sdk Resolver Failure: MSB4243: blah blah.

@benvillalobos

Copy link
Copy Markdown
Member Author

@dsplaisted what's the easiest way to reproduce a generic resolver exception?

@dsplaisted

Copy link
Copy Markdown
Member

Go into the sdk-manifests folder of your .NET SDK and update one of the json files (for example C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.sdk.android\WorkloadManifest.json to be invalid json (after making a backup, of course).

I think that should trigger an exception.

You may want to use a separate local SDK for testing this so that your changes don't prevent you from building all projects on your system. Let me know if you need help with that, the artifacts\sdk-build-env.bat and eng\dogfood.cmd scripts in the SDK repo set the environment variables that you would need to in order to use a local SDK.

@benvillalobos

Copy link
Copy Markdown
Member Author

@jeffkl FYI. Does this PR sound reasonable?

@jeffkl

jeffkl commented Aug 18, 2021

Copy link
Copy Markdown
Contributor

@benvillalobos Yeah ideally a resolver would never throw an exception unless there's a bug. The idea with the original design was to keep trying other resolvers as a fallback in case another can handle it. But at the moment there are only 3 resolvers:

  1. .NET Core SDK resolver - Resolves SDKs in the .NET Core SDK
  2. NuGet SDK resolver - Resolves SDKs from a NuGet package
  3. Default SDK resolver - Resolves SDKs next to MSBuild

None of these really "fall back" to another if there's an error, so it does make sense to just fail evaluation if something is wrong.

@benvillalobos

benvillalobos commented Aug 18, 2021 •

Copy link
Copy Markdown
Member Author

Go into the sdk-manifests folder of your .NET SDK and update one of the json files (for example C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.sdk.android\WorkloadManifest.json to be invalid json (after making a backup, of course).
I think that should trigger an exception.

Confirmed the fix works locally when I do this on a standalone sdk.

Old Error

PS C:\src\temp\8-18> C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\dotnet.exe build
Microsoft (R) Build Engine version 17.0.0-dev-21418-01+d592862ed for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\src\temp\8-18\8-18.csproj : warning MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed to run. 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,3): warning MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed to run. 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,38): error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found. [C:\src\temp\8-18\8-18.csproj]

Build FAILED.

New Error

PS C:\src\temp\8-18> C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\dotnet.exe build
Microsoft (R) Build Engine version 17.0.0-dev-21418-01+92d5334ca for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\src\temp\8-18\8-18.csproj : error MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk": 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\temp\8-18\8-18.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

Build FAILED.

PR is ready for review.

None of these really "fall back" to another if there's an error, so it does make sense to just fail evaluation if something is wrong.

Are resolvers eventually expected to fall back? Even in the event of an exception? It looks like resolvers can already log errors and continue. It's specifically when they throw that they won't be able to fall back.

IMO that behavior is fine, and each resolver should catch exceptions and turn them into errors if they want some future resolver to pick up where it couldn't. Thoughts?

@benvillalobos
benvillalobos marked this pull request as ready for review August 18, 2021 18:54
@jeffkl

jeffkl commented Aug 18, 2021

Copy link
Copy Markdown
Contributor

Are resolvers eventually expected to fall back?

The functionality is there because we'll continue on if an error occurs. The only thing is that there's no logic for a resolver to come back and say the error is fatal. We could add a new value to the SDK result so that the contract is:

  • Unhandled exceptions fail evaluation for a particular SDK resolver
    -or-
  • Returning "Fatal" error disables fallbacks if an SDK resolver knows that something should have worked but didn't.

I'm not a fan of having unhandled exceptions be the only way a resolver can fail evaluation since we have an API. For the above case when WorkloadManifest.json has invalid JSON, the SDK resolver could catch that and wrap it in a different exception that might affect what is logged.

@dsplaisted

Copy link
Copy Markdown
Member

This is way better, but there are still two errors and the second one is not really accurate:

C:\src\temp\8-18\8-18.csproj : error MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk": 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\temp\8-18\8-18.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

If possible I would like it if we could just fail with the SDK resolver error (MSB4242) and not the SDK not found error (MSB4236).

@benvillalobos

Copy link
Copy Markdown
Member Author

@dsplaisted This is slightly more annoying than expected. The way it currently works is:

SDKResolverService logs an error when an exception is thrown. It returns the result, which is picked up by the evaluator which needs to fail the build immediately.

The problem is it needs to fail the build with a message.

We could defer the message that the resolver service would have logged, but the evaluator doesn't have enough info to properly log that message (resolver name, exception message).

I propose we give SdkResult an Enumberable<string> Args field that we populate when an exception is thrown. This would allow Evaluator to log the error and any extra info needed based on resource.

Do you know what's expected to populate Errors and Warnings of an SDKResult? Is it the code? Is it the resource name of the message? Full error message? I'm thinking of using either the resource name or the code and special casing them in the evaluator.

@dsplaisted

Copy link
Copy Markdown
Member

If we need to add error information to SdkResult, then I would just have it be a string, and it should be localized and formatted before being set on the SdkResult.

We might also be able to communicate the error back to the evaluator by letting the exception propogate, or by throwing a new one with the right information.

@benvillalobos

benvillalobos commented Aug 19, 2021 •

Copy link
Copy Markdown
Member Author

We might also be able to communicate the error back to the evaluator by letting the exception propogate, or by throwing a new one with the right information.

going with this. As a result I've had to turn MSB4242 into a generic "SDK Resolver Failed: {0}" message, passing the exception's message as the arg. Where the exception's message is the SDKResolverService's error pulled from resources and string.formatted.

I had to remove the error codes from the NuGet exception message and generic sdk resolver exception message. Otherwise we would see "MSB4242: SDK Resolver failure: MSB4243 NuGet SDK failure...."

@benvillalobos benvillalobos removed the WIP label Aug 19, 2021
Comment on lines 97 to 98

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
_logger.ErrorCount.ShouldBe(1);
_logger.Errors.First().Code.ShouldBe("MSB4242");
_logger.Errors.Single().Code.ShouldBe("MSB4242");

Little trick, though this isn't the best use of it. Single throws if Errors is not a singleton.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know this wasn't in the warning, but maybe include all of e as an inner exception? (Also elsewhere) Then we can stack trace, etc.

Also, should the Exception (including above) be more specific?

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.

I know this wasn't in the warning, but maybe include all of e as an inner exception? (Also elsewhere) Then we can stack trace, etc.

Makes sense

Comment thread src/Build/Evaluation/Evaluator.cs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a particular exception we expect this to throw?

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.

I was thinking of creating an SdkResolverException of some kind, but couldn't think of anything specific to add to it. In theory it could hold the resolver's name, sdk name, basically whatever's being used in this string.format. Then the evaluator would do exactly what's happening here.

Now that I'm actively thinking about it, having the evaluator check specifically for an sdkresolverexception might make more sense. If anything else throws (outside of the resolvers actually resolving) then we'd immediately be aware of a new 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.

Yeah, I don't think we should be throwing the base Exception class. There may already be an exception type defined that would make sense here, so we might not need to create a new one. @rainersigwald, any suggestiens?

@dsplaisted dsplaisted left a comment

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.

Looks good modulo the exception type. I'd also like to see the updated output when it fails.

@benvillalobos

Copy link
Copy Markdown
Member Author

Using this method:

Go into the sdk-manifests folder of your .NET SDK and update one of the json files (for example C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.sdk.android\WorkloadManifest.json to be invalid json (after making a backup, of course).
I think that should trigger an exception.

New Error Message:

C:\src\temp\8-18>"C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\dotnet.exe" build    
Microsoft (R) Build Engine version 17.0.0-dev-21420-01+5df152759 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\src\temp\8-18\8-18.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "'s' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8."".

Build FAILED.

C:\src\temp\8-18\8-18.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "'s' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8."".
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.15

@benvillalobos

benvillalobos commented Aug 20, 2021 •

Copy link
Copy Markdown
Member Author

adding microsoft.net.workload.foo to the sdk-manifests/version folder to break the resolver in a different way.

New Message:

C:\src\temp\8-18>"C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\dotnet.exe" build
Microsoft (R) Build Engine version 17.0.0-dev-21420-01+5df152759 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\src\temp\8-18\8-18.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "Could not find file 'C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\sdk-manifests\6.0.100\microsoft.net.workload.test\WorkloadManifest.json'."".

Build FAILED.

C:\src\temp\8-18\8-18.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "Could not find file 'C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\sdk-manifests\6.0.100\microsoft.net.workload.test\WorkloadManifest.json'."".
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.25

Going to remove the trailing . on MSB4242 to make the messages slightly less messy.

@benvillalobos benvillalobos changed the title Fail Builds When SDKResolvers Throw Exceptions Fail Builds Fast When SDKResolvers Throw Exceptions Aug 20, 2021
@benvillalobos

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@benvillalobos

Copy link
Copy Markdown
Member Author

@rainersigwald https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk this was the closest thing I could find relating to any sdk resolver docs. Should we have a file in this repo that has documentation on resolvers?

@rainersigwald

Copy link
Copy Markdown
Member

Yeah, put something in the specs folder please.

@benvillalobos

Copy link
Copy Markdown
Member Author

@rainersigwald added a very rough document that specifically mentions resolvers failing the build quickly with msb4242. Let me know if we should add more. I'd prefer to keep the doc update specific to what this PR covers, then make an issue that tracks adding more detail to the doc.

@rainersigwald rainersigwald left a comment

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.

Looks good overall, and adding a new exception type is fine by me. Some nits on diagnosability.

result.Path.ShouldBe("resolverpath1");
_logger.Warnings.Select(i => i.Message).ShouldBe(new [] { "The SDK resolver \"MockSdkResolverThrows\" failed to run. EXMESSAGE" });
// When an SDK resolver throws, the expander will catch it and stop the build.
Should.Throw<SdkResolverException>(() => SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false));

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.

Assert MockSdkResolverThrows and EXMESSAGE still?

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.

No warnings or errors are logged in this codepath anymore, and there are other tests that verify warnings/errors.

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 was asking (confusingly) if we should verify that the exception's data fields were populated correctly.

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.

Added checks to ensure MockSdkResolverThrows and EXMESSAGE are contained in the exception's message.

loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "CouldNotRunNuGetSdkResolver", MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message);
continue;
// The NuGet-based SDK resolver failed to run because NuGet assemblies could not be located. Check your installation of MSBuild or set the environment variable "{0}" to the folder that contains the required NuGet assemblies. {1}
throw new SdkResolverException("CouldNotRunNuGetSdkResolver", sdkResolver, sdk, e, MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message);

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.

So I know this is what was here before, but Exception.Message is a bit of a code smell since it hides information (specifically the stack at the point of failure). Should that just be

Suggested change
throw new SdkResolverException("CouldNotRunNuGetSdkResolver", sdkResolver, sdk, e, MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message);
throw new SdkResolverException("CouldNotRunNuGetSdkResolver", sdkResolver, sdk, e, MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.ToString());

?

@benvillalobos benvillalobos Aug 24, 2021 •

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.

It looks like ProjectErrorUtilities.ThrowInvalidProject prepends the error code to every line of the stack trace. Looks a little messy, is this still preferred? (this is with the Evaluator throwing using e.Message)

Build FAILED.

C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.Text.Json.JsonReaderException: 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in System.Text.Json.dll:token 0x60000de+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenUntilAfterAllCommentsAreSkipped(Byte marker) in System.Text.Json.dll:token 0x6000315+0x1fc
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker) in System.Text.Json.dll:token 0x6000311+0x3c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker) in System.Text.Json.dll:token 0x6000310+0x24
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in System.Text.Json.dll:token 0x60002fc+0x113
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.Read() in System.Text.Json.dll:token 0x60002e8+0x8
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.Utf8JsonStreamReader.Read() in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x60000ef+0x12f
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinition(WorkloadId id, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000082+0x2ff
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinitions(Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600007c+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String id, String informationalPath, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000079+0x124
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, String informationalPath) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000084+0x23
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600009e+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000099+0x8a
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x6000019+0x5b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x600001c+0x50
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 118""
    0 Warning(s)
    1 Error(s)

}
catch (SdkResolverException e)
{
ProjectErrorUtilities.ThrowInvalidProject(importElement.SdkLocation, "SDKResolverCriticalFailure", e.Message);

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.

Likewise here this seems like it might be able to be better. e.InnerException.ToString()?

@benvillalobos benvillalobos Aug 24, 2021 •

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.

If we log the inner exception's message here we lose the stack trace & resource message that was logged when the resolver failed and end up with:

C:\src\issues\6763-sdkresolvers\console>"C:\Users\bevillal\Downloads\dotnet-sdk-6.0.100-preview.7.21379.14-win-x64\dotnet.exe" build
Microsoft (R) Build Engine version 17.0.0-dev-21424-01+2cafba516 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "'s' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8."

Build FAILED.

C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "'s' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8."
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.18

See the above comment for what it would look like if we use e.ToString()

Below is e.ToString() with the resolverservice logging its e.ToString(). This is just too verbose imo.

C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "Microsoft.Build.BackEnd.SdkResolution.SdkResolverException: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.Text.Json.JsonReaderException: 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in System.Text.Json.dll:token 0x60000de+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenUntilAfterAllCommentsAreSkipped(Byte marker) in System.Text.Json.dll:token 0x6000315+0x1fc
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker) in System.Text.Json.dll:token 0x6000311+0x3c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker) in System.Text.Json.dll:token 0x6000310+0x24
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in System.Text.Json.dll:token 0x60002fc+0x113
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.Read() in System.Text.Json.dll:token 0x60002e8+0x8
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.Utf8JsonStreamReader.Read() in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x60000ef+0x12f
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinition(WorkloadId id, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000082+0x2ff
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinitions(Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600007c+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String id, String informationalPath, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000079+0x124
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, String informationalPath) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000084+0x23
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600009e+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000099+0x8a
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x6000019+0x5b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x600001c+0x50
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 118"
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:  ---> System.Text.Json.JsonReaderException: 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in System.Text.Json.dll:token 0x60000de+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenUntilAfterAllCommentsAreSkipped(Byte marker) in System.Text.Json.dll:token 0x6000315+0x1fc
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker) in System.Text.Json.dll:token 0x6000311+0x3c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker) in System.Text.Json.dll:token 0x6000310+0x24
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in System.Text.Json.dll:token 0x60002fc+0x113
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.Read() in System.Text.Json.dll:token 0x60002e8+0x8
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.Utf8JsonStreamReader.Read() in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x60000ef+0x12f
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinition(WorkloadId id, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000082+0x2ff
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinitions(Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600007c+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String id, String informationalPath, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000079+0x124
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, String informationalPath) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000084+0x23
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600009e+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000099+0x8a
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x6000019+0x5b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x600001c+0x50
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 118
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    --- End of inner exception stack trace ---
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 132
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.<>n__0(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in Microsoft.Build.dll:token 0x600169e+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.<>c__DisplayClass3_0.<ResolveSdk>b__1() in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\CachingSdkResolverService.cs:line 55
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) in System.Private.CoreLib.dll:token 0x60013b6+0x1c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) in System.Private.CoreLib.dll:token 0x60013b7+0x22
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Lazy`1.CreateValue() in System.Private.CoreLib.dll:token 0x60013bc+0x74
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Lazy`1.get_Value() in System.Private.CoreLib.dll:token 0x60013c2+0xa
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\CachingSdkResolverService.cs:line 58
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.MainNodeSdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\MainNodeSdkResolverService.cs:line 95
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError) in C:\src\git\msbuild\src\Build\Evaluation\Evaluator.cs:line 1790"
    0 Warning(s)
    1 Error(s)

Below is e.InnerException.ToString() when resolverservice logs its e.ToString(). Here we don't get which sdkresolver failed resolving which sdk.

C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "System.Text.Json.JsonReaderException: 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in System.Text.Json.dll:token 0x60000de+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenUntilAfterAllCommentsAreSkipped(Byte marker) in System.Text.Json.dll:token 0x6000315+0x1fc
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker) in System.Text.Json.dll:token 0x6000311+0x3c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker) in System.Text.Json.dll:token 0x6000310+0x24
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in System.Text.Json.dll:token 0x60002fc+0x113
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.Read() in System.Text.Json.dll:token 0x60002e8+0x8
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.Utf8JsonStreamReader.Read() in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x60000ef+0x12f
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinition(WorkloadId id, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000082+0x2ff
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinitions(Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600007c+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String id, String informationalPath, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000079+0x124
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, String informationalPath) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000084+0x23
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600009e+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000099+0x8a
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x6000019+0x5b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x600001c+0x50
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 118"
    0 Warning(s)
    1 Error(s)

And here is evaluator logging e.Message while resolverservice logs e.ToString(). This one is ideal because we get:

  1. Overall MSB4242.
  2. Which SDKresolver failed, and which SDK it failed to resolve
  3. Inner exception ('s' is an invalid...)
  4. Stack trace
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.Text.Json.JsonReaderException: 's' is an invalid start of a property name. Expected a '"'. LineNumber: 14 | BytePositionInLine: 8.
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) in System.Text.Json.dll:token 0x60000de+0x0
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenUntilAfterAllCommentsAreSkipped(Byte marker) in System.Text.Json.dll:token 0x6000315+0x1fc
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker) in System.Text.Json.dll:token 0x6000311+0x3c
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker) in System.Text.Json.dll:token 0x6000310+0x24
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.ReadSingleSegment() in System.Text.Json.dll:token 0x60002fc+0x113
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at System.Text.Json.Utf8JsonReader.Read() in System.Text.Json.dll:token 0x60002e8+0x8
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.Utf8JsonStreamReader.Read() in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x60000ef+0x12f
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinition(WorkloadId id, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000082+0x2ff
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadDefinitions(Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600007c+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String id, String informationalPath, Utf8JsonStreamReader& reader) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000079+0x124
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, String informationalPath) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000084+0x23
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x600009e+0x2b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadManifestReader.dll:token 0x6000099+0x8a
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x6000019+0x5b
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) in Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.dll:token 0x600001c+0x50
C:\src\issues\6763-sdkresolvers\console\console.csproj : error MSB4242:    at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio) in C:\src\git\msbuild\src\Build\BackEnd\Components\SdkResolution\SdkResolverService.cs:line 118""
    0 Warning(s)
    1 Error(s)

Going with the last one unless another is preferred.

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.

That last one looks good. A bit chatty but this is always a resolver bug so I prefer to get a bunch of info out. Please comment the Message call so it stands out to future code smellers.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Aug 29, 2021
@benvillalobos

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@benvillalobos

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@benvillalobos

Copy link
Copy Markdown
Member Author

Looks like it's
Running tests: D:\a\1\s\artifacts\bin\Microsoft.Build.CommandLine.UnitTests\Debug\net472\Microsoft.Build.CommandLine.UnitTests.dll [net472|x86] that's the problem. Something in there seems to be hanging or waiting for some state that isn't happening. I can't repro on my machine though.

@benvillalobos

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@benvillalobos

benvillalobos commented Sep 1, 2021 •

Copy link
Copy Markdown
Member Author

CI passed twice in a row. Must have been some flakiness. @dotnet/kitten

@rainersigwald
rainersigwald merged commit 864047d into dotnet:main Sep 1, 2021
DustinCampbell added a commit to DustinCampbell/msbuild that referenced this pull request Jul 23, 2026
src/Build/Resources/xlf/Strings.en.xlf is the last surviving *.en.xlf
file, an orphan left over from a change to the localized languages list.

History:
 - The repo once overrode XlfLanguages to force English satellite
   assemblies: "en;cs;de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant".
 - a66a243 "Use default XlfLanguages" (2021-06-18, merged via PR dotnet#6595)
   removed that override, reverting to the XliffTasks default, which
   excludes 'en' (English is the source language). That commit deleted all
   *.en.xlf files across the repo.
 - 864047d "Fail Builds Fast When SDKResolvers Throw Exceptions (dotnet#6763)"
   then accidentally re-added src/Build/Resources/xlf/Strings.en.xlf via a
   stale branch/merge; the PR itself was unrelated to localization.

Because 'en' is no longer in XlfLanguages, UpdateXlf never regenerates or
validates this file, and no other project has an *.en.xlf counterpart. A
full build.cmd with it removed succeeds with 0 warnings/0 errors and does
not regenerate it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fail fast when MSBuild SDK resolver throws an exception

5 participants