You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
DynamicallyAccessedMembers does not mark the type if passed in as string #1537
Per annotations, it is perfectly valid to call Activator.CreateInstance due to the annotation on the parameter of CreateInstanceOf. Linker doesn't produce any warnings from the code above.
But when executed, the application fails with:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'type') at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at lib.Test.CreateInstanceOf(String n) in F:\ILLinker\repro\TypeNameRep\lib\Class1.cs:line 16 at lib.Test.TestIt() in F:\ILLinker\repro\TypeNameRep\lib\Class1.cs:line 10 at Program.Main(String[] args) in F:\ILLinker\repro\TypeNameRep\TypeNameRep\Program.cs:line 17
The failure is because Type.GetType returns null. In the trimmed assembly there's actually no type GenOut.
There are two weird things here:
GenOut<>.ctor() should be kept, but for some reason we leave it out
Even if I force include GenOut<> (by having a direct typeref to it), GenIn also needs to be kept, which won't happen either
Interestingly changing the code to call CreateInstanceOf("lib.GenOut`1") actually works, the GenOut<>.ctor is kept and the app fails because it's invalid to instantiate open generic type.
Activity
vitek-karas commentedon Oct 6, 2020
Interestingly changing the code to call
CreateInstanceOf("lib.GenOut`1")actually works, theGenOut<>.ctoris kept and the app fails because it's invalid to instantiate open generic type.vitek-karas commentedon Oct 6, 2020
I also found dotnet/sdk#13999 when working on this bug.
vitek-karas commentedon Sep 16, 2022
This has been fixed, the repro from the issue above works now.