dotnet / dotnet/sdk

GenAPI crashes with StackOverflowException when processing System.Runtime.dll from targeting packs

Open
#54,778 0 comments 0 reactions 0 assignees View on GitHub
Area-GenAPI untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

# GenAPI crashes with StackOverflowException when processing System.Runtime.dll from targeting packs

## Description

GenAPI crashes with a `StackOverflowException` (process abort) when generating reference source from `System.Runtime.dll` in the `microsoft.netcore.app.ref/8.0.0` targeting pack. The crash occurs in Roslyn's Workspace Simplifier (`CSharpNameReducer.VisitQualifiedName`) which enters infinite recursion on a thread pool thread.

This was discovered while working on migrating targeting pack generation in [dotnet/source-build-assets](https://github.com/dotnet/source-build-assets/issues/1313) from IL-based tooling to GenAPI/C#-based generation. Other assemblies in the `microsoft.netcore.app.ref/8.0.0` targeting pack (101 of 102) are generated successfully when processed individually — only `System.Runtime.dll` triggers this crash. Other targeting pack versions have not been tested.

## Steps to Reproduce

1. Create a project (`repro.csproj`):

```xml


net8.0
true
true
false
false
false
true





$(NuGetPackageRoot)microsoft.netcore.app.ref/8.0.0/ref/net8.0
$(MSBuildProjectDirectory)/output











```

2. Build:

```bash
dotnet build
```

3. Process crashes (core dump, exit code 134 on Linux).

## Expected Behavior

GenAPI generates reference source for `System.Runtime.dll` without crashing.

## Actual Behavior

The process aborts with a `StackOverflowException`. The crash originates in Roslyn's Workspace Simplifier performing name reduction:

```
Stack overflow.
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer.SimplifyName(...)
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer+Rewriter.VisitIdentifierName(...)
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer+Rewriter.VisitAliasQualifiedName(...)
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer+Rewriter.VisitQualifiedName(...)
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer+Rewriter.VisitQualifiedName(...)
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer+Rewriter.VisitQualifiedName(...)
... (repeating)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitAttribute(...)
at Microsoft.CodeAnalysis.Simplification.AbstractSimplificationService`4...ReduceOneNodeOrTokenAsync(...)
at System.Threading.Tasks.Parallel...ForEachAsync(...)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
```

## Environment

- Microsoft.DotNet.GenAPI.Task: 11.0.100-preview.6.26309.107
- .NET SDK: 11.0.100-preview.5.26227.104
- OS: Linux (Ubuntu)

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.