dotnet / dotnet/roslyn

Script compilation takes a dependency on host System.Private.CoreLib

Open
#79,625 0 comments 0 reactions 0 assignees View on GitHub
Area-Interactive untriaged
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**:
Microsoft.CodeAnalysis.CSharp.Scripting 4.14.0

**Steps to Reproduce**:

```csharp
var code = "2+2";
string[] assemblyPaths = [/* Paths to .NET Standard 2.1 reference assemblies */];
var options = ScriptOptions.Default.WithReferences(assemblyPaths);
var script = CSharpScript.Create(code, options);
var compilation = script.GetCompilation();
var assemblyStream = new MemoryStream();
var emitResult = compilation.Emit(assemblyStream);
```

**Expected Behavior**:
`emitResult.Success == true`
The compiled assembly depends only on .NET Standard 2.1.

**Actual Behavior**:
`emitResult.Success == false`
`compilation.References` contains a reference to host `System.Private.CoreLib`.

**Notes**
Looks very similar to #8506, which is marked as fixed. The code from that bug report works correctly, probably the same approach would work for fixing this one as well.

Contributor guide

Open the contributing guide

Research direction

Start with the CSharpScript.Create and GetCompilation repro in the issue, then compare its reference setup with the approach used for #8506. Investigate why compilation.References includes host System.Private.CoreLib when assemblyPaths contains .NET Standard 2.1 reference assemblies. Done means Emit succeeds and the compiled assembly depends only on .NET Standard 2.1.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.