Repository navigation
Fail Builds Fast When SDKResolvers Throw Exceptions - #6763
Conversation
|
@dsplaisted what's the easiest way to reproduce a generic resolver exception? |
|
Go into the sdk-manifests folder of your .NET SDK and update one of the json files (for example 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 |
|
@jeffkl FYI. Does this PR sound reasonable? |
|
@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:
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. |
Confirmed the fix works locally when I do this on a standalone sdk. Old ErrorNew ErrorPR is ready for review.
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? |
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:
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. |
|
This is way better, but there are still two errors and the second one is not really accurate:
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). |
|
@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 Do you know what's expected to populate |
|
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. |
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...." |
There was a problem hiding this comment.
| _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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Is there a particular exception we expect this to throw?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
bd4a52e to
5df1527
Compare
dsplaisted
left a comment
There was a problem hiding this comment.
Looks good modulo the exception type. I'd also like to see the updated output when it fails.
|
Using this method:
New Error Message: |
|
adding New Message:Going to remove the trailing |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@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? |
|
Yeah, put something in the specs folder please. |
…ns early when and logs an error when we fail to resolve an SDK
779686c to
2cafba5
Compare
|
@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
left a comment
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Assert MockSdkResolverThrows and EXMESSAGE still?
There was a problem hiding this comment.
No warnings or errors are logged in this codepath anymore, and there are other tests that verify warnings/errors.
There was a problem hiding this comment.
I was asking (confusingly) if we should verify that the exception's data fields were populated correctly.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
| throw new SdkResolverException("CouldNotRunNuGetSdkResolver", sdkResolver, sdk, e, MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message); | |
| throw new SdkResolverException("CouldNotRunNuGetSdkResolver", sdkResolver, sdk, e, MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.ToString()); |
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Likewise here this seems like it might be able to be better. e.InnerException.ToString()?
There was a problem hiding this comment.
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:
- Overall MSB4242.
- Which SDKresolver failed, and which SDK it failed to resolve
- Inner exception ('s' is an invalid...)
- 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.
There was a problem hiding this comment.
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.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Looks like it's |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
CI passed twice in a row. Must have been some flakiness. @dotnet/kitten |
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.
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
SdkResolverExceptionMSB4242.Testing
Tested on a local standalone sdk. See comments below.
Notes
MSB4242: Sdk Resolver Failure: MSB4243: blah blah.