MSBuild new Project hides Could not load file or assembly 'System.Collections.Immutable behind Microsoft.Build.Exceptions.InvalidProjectFileException
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
Real exception (Could not load file or assembly 'System.Collections.Immutable) is hidden behind (Microsoft.Build.Exceptions.InvalidProjectFileException: 'The SDK 'Microsoft.NET.Sdk' specified could not be found. PathToProject).
I already fixed the underlying issue but I think this should not be hidden like this, it should probably be set as an inner exception or something like that.
### Full detail of exceptions being thrown
-> **FIRST exception that happens**
System.Runtime.InteropServices.COMException: 'Element not found. (Exception from HRESULT: 0x80070490)' in:

-> **SECOND exception that happens and that I would expect to be reported**
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Stacktrace:
```
at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion)
at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
```

-> **Actual exception that I get without inner exceptions:**
"Microsoft.Build.Exceptions.InvalidProjectFileException: 'The SDK 'Microsoft.NET.Sdk' specified could not be found. PathToProject"
Stacktrace:
`at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)`

### Steps to Reproduce
The issue happens when trying to create
``` cs
new Project(fullPath, globalProperties, null, projectCollection);
```
### Expected Behavior
I would expect it to fail with "System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0" or at least have that as the inner exception of the error that I'm getting (Microsoft.Build.Exceptions.InvalidProjectFileException: 'The SDK 'Microsoft.NET.Sdk' specified could not be found. PathToProject")
### Actual Behavior
The actual error is "Microsoft.Build.Exceptions.InvalidProjectFileException: 'The SDK 'Microsoft.NET.Sdk' specified could not be found. PathToProject" and does not contain any indication of that the actual error is
### Versions & Configurations
MSBuild version 16.10.1.27004
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.