Hot reload fails to flow generic constraints to the inherited class
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
### Description
When adding a new class with generic constraints and passing it down to the parent class the update seems to apply successfully but the generated type is invalid.
### Reproduction Steps
Run the following program with `dotnet watch` or from Visual Studio and uncomment L10 when the application is running.
```csharp
using System.Reflection.Metadata;
[assembly: MetadataUpdateHandler(typeof(MetadataUpdateHandler))]
Console.WriteLine("Ready..");
await Task.Delay(-1);
public interface ICat;
internal abstract class Holder;
//internal sealed class CatHolder : Holder where T : ICat; //Uncomment this line when the application is running.
internal static class MetadataUpdateHandler
{
private static void UpdateApplication(Type[]? _)
{
try
{
Console.WriteLine("Update..");
GC.KeepAlive(typeof(MetadataUpdateHandler).Assembly.GetTypes());
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
```
### Expected behavior
The update is applied successfully with the correct generic constraints.
### Actual behavior
The following exception is printed to the console.
```
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
GenericArguments[0], 'T', on 'Holder`1[T]' violates the constraint of type parameter 'T'.
at System.Reflection.RuntimeModule.GetDefinedTypes()
at System.Reflection.RuntimeModule.GetTypes()
at MetadataUpdateHandler.UpdateApplication(Type[] _)
System.TypeLoadException: GenericArguments[0], 'T', on 'Holder`1[T]' violates the constraint of type parameter 'T'.
```
### Regression?
No, fails on .NET 6 and .NET 8.
### Known Workarounds
_No response_
### Configuration
9.0.100-preview.2.24157.14
Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.10.0 Preview 2.0
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.