dotnet / dotnet/linker

Linker doesn't trim IEnumerable interface in console app even if it's not used

Open
#3,189 10 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

```csharp
internal class Program
{
static void Main(string[] args)
{
var t = new CustomClass();
}

private sealed class CustomClass : IEnumerable
{
public IEnumerator GetEnumerator()
{
return new CustomEnumerator();
}
}

private sealed class CustomEnumerator : IEnumerator
{
public object Current => throw new NotImplementedException();

public bool MoveNext()
{
throw new NotImplementedException();
}

public void Reset()
{
throw new NotImplementedException();
}
}
}
```

![image](https://user-images.githubusercontent.com/14861420/213803968-e84126e7-0156-48ac-ac2e-9827994b644e.png)

Npgsql implements that interface for `NpgsqlDataReader` (because `NpgsqlDataReader` inherits from `DbDataReader`, inheriting `IEnumerable`). Our implementation of `GetEnumerator` returns `System.Data.Common.DbEnumerator`, which touches quite a bit of `IDataReader` methods, and some of them are not AOT friendly (mostly related to size).

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.