From 78ae64a08b3025140f0f97f27c7778e421e81553 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:02:54 +0000 Subject: [PATCH 1/2] Initial plan From 742bd92628d4b1968cecfe73ee705dad7ff85d83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:33:00 +0000 Subject: [PATCH 2/2] Fix COM class generator to handle generic types in hint names Replace < and > with { and } in hint names to avoid ArgumentException when generating source for generic COM classes. Add test case to validate the fix. Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com> --- .../ComClassGenerator.cs | 4 +++- .../ComClassGeneratorOutputShape.cs | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs index 918643a6ff6898..3169f93b0f1076 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs @@ -55,7 +55,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) writer.WriteLine(classInfoType.ToFullString()); writer.WriteLine(); writer.WriteLine(attribute); - context.AddSource(className, writer.ToString()); + // Replace < and > with { and } to make valid hint names for generic types + string hintName = className.Replace('<', '{').Replace('>', '}'); + context.AddSource(hintName, writer.ToString()); }); } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorOutputShape.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorOutputShape.cs index cc3dc85bbe5e46..c00ff13aae59f3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorOutputShape.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorOutputShape.cs @@ -68,6 +68,27 @@ partial class E : C await VerifySourceGeneratorAsync(source, "C", "D", "E"); } + [Fact] + public async Task GenericComClass() + { + string source = """ + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + [GeneratedComInterface] + partial interface INativeAPI + { + } + + [GeneratedComClass] + partial class GenericClass : INativeAPI where T : class, new() + { + } + """; + + await VerifySourceGeneratorAsync(source, "GenericClass`1"); + } + private static async Task VerifySourceGeneratorAsync(string source, params string[] typeNames) { GeneratedShapeTest test = new(typeNames)