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 }}
Repository navigation
NativeAOT MakeGenericType fails to activate reflected generic type when generic parameter has self-referential interface constraint #126604
NativeAOT throws at runtime when creating a closed generic type via:
typeof(GenericType<,>).MakeGenericType(...)
Activator.CreateInstance(...)
if the generic type parameter has this constraint:
whereTRequest:struct,IRequest<TRequest,TResponse>
The same code works if the self-referential interface constraint is removed and replaced with just:
whereTRequest:struct
This looks incorrect, because the closed generic instantiation is valid and used at runtime with compatible type arguments, but NativeAOT does not preserve the required metadata/native code.
NativeAOT should handle constraints correctly in this case since it generates metadata if I remove the constraint.
Actual behavior
Runtime throws: Unhandled exception. System.NotSupportedException: '...GenericType`2[...TestRequest,System.String]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published.
Activity
dotnet-policy-service commentedon Apr 7, 2026
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.
Handle canonical types in casting logic (#127146)
MichalStrehovsky commentedon Apr 22, 2026
The fix is getting revered, reopen.
Handle canonical types in constraints checks (dotnet#129278)
Handle canonical types in casting logic (#127146)
Handle canonical types in constraints checks (#129278)
Handle canonical types in constraints checks (dotnet#129278)