Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload fails to flow generic constraints to the inherited class #73448

Open
mikelle-rogers opened this issue May 13, 2024 · 1 comment
Open
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@mikelle-rogers
Copy link
Member

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.

using System.Reflection.Metadata;

[assembly: MetadataUpdateHandler(typeof(MetadataUpdateHandler))]

Console.WriteLine("Ready..");

await Task.Delay(-1);

public interface ICat;
internal abstract class Holder<T>;
//internal sealed class CatHolder<T> : Holder<T> 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

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 13, 2024
@mikelle-rogers
Copy link
Member Author

mikelle-rogers commented May 13, 2024

Original issue filed here by @aromaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants