dotnet / dotnet/linker

Overload resolution for Activator.CreateInstance

Open
#1,856 0 comments 0 reactions 1 assignee Claimed by @mateoatr View on GitHub
area-Linker: DataFlow
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

Linker tries to guess the constructor to keep for Activator.CreateInstance by counting the number of parameters passed to the constructor.

Unfortunately, the reflection stack is aware of the `ParamArrayAttribute` which is the mechanism that C# uses to distinguish between `object[]` and `params object[]`. So if any of the constructors has a member with this attribute, the counting logic might not work.

```csharp
Activator.CreateInstance(typeof(Foo), new object[] { 1, 2, 3, 4, 5 });

class Foo
{
// Should be kept
public Foo(int x, params object[] y) => Console.WriteLine(y.Length);
}
```

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.