Skip to content

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

@vonzshik

Description

@vonzshik
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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions