dotnet / dotnet/msbuild

MSBuild new Project hides Could not load file or assembly 'System.Collections.Immutable behind Microsoft.Build.Exceptions.InvalidProjectFileException

Open
#6,654 2 comments 1 reaction 0 assignees View on GitHub
needs-design triaged
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:
![Stacktrace first Exception](https://user-images.githubusercontent.com/14632949/124531562-18d18180-de52-11eb-89fd-dd430fd6bdd5.png)
-> **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)
```
![Second exception full stacktrace](https://user-images.githubusercontent.com/14632949/124532499-0a846500-de54-11eb-8ac5-75b33a53ffe1.png)
-> **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)`
![Third and actual stacktrace that I get](https://user-images.githubusercontent.com/14632949/124532773-7ebf0880-de54-11eb-9d18-2afb71d5a6b3.png)

### 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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.