From bc78804f5d1486bb7313d1661992626640091bf1 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 30 May 2023 14:13:17 -0700 Subject: [PATCH] [release/8.0-preview5] Use fully qualified type names for parameters and don't copy parameter attributes (#86899) * Use fully qualified type names for parameters and don't copy parameter attributes The issue https://github.com/dotnet/source-build/issues/3483 looks similar to the issues I found before fixing in https://github.com/dotnet/runtime/pull/86731. The relevant changes were in ComMethodContext.cs. If it's the same issue I was hitting, the attribute syntax was being copied over without adding 'using' statements or changing the attribute name to be fully qualified. I haven't validated yet, but this should fix it by just not copying the attributes for the parameters since they're not strictly necessary. * Add test for change --- .../ComInterfaceGenerator/ComMethodContext.cs | 1 + .../CodeSnippets.cs | 18 ++++++++++++++++++ .../Compiles.cs | 1 + 3 files changed, 20 insertions(+) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs index daf7c149adf92..f4aa8979a5a1f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComMethodContext.cs @@ -109,6 +109,7 @@ private MethodDeclarationSyntax CreateUnreachableExceptionStub() .WithAttributeLists(List()) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier( ParseName(OriginalDeclaringInterface.Info.Type.FullTypeName))) + .WithParameterList(ParameterList(SeparatedList(GenerationContext.SignatureContext.StubParameters))) .WithExpressionBody(ArrowExpressionClause( ThrowExpression( ObjectCreationExpression( diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs index 38f9f9f8e262d..2eeb5a2b12140 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs @@ -291,6 +291,24 @@ partial interface IComInterface2 } """; + public string ComInterfaceInheritanceWithParametersWithAttributes => $$""" + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + {{GeneratedComInterface}} + partial interface IComInterface + { + void Method([MarshalUsing(typeof(Utf8StringMarshaller))] string myString); + } + {{GeneratedComInterface}} + partial interface IComInterface1 : IComInterface + { + void Method2([MarshalUsing(typeof(Utf8StringMarshaller))] string myString); + } + + """; + public class ManagedToUnmanaged : IVirtualMethodIndexSignatureProvider { public MarshalDirection Direction => MarshalDirection.ManagedToUnmanaged; diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs index c866713b9d402..5d74af748ce0d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs @@ -335,6 +335,7 @@ public static IEnumerable ComInterfaceSnippetsToCompile() CodeSnippets codeSnippets = new(new GeneratedComInterfaceAttributeProvider()); yield return new object[] { ID(), codeSnippets.DerivedComInterfaceType }; yield return new object[] { ID(), codeSnippets.ComInterfaceParameters }; + yield return new object[] { ID(), codeSnippets.ComInterfaceInheritanceWithParametersWithAttributes }; } [Theory]