From a9ad8ccc65324224603a9c5be4a78539460f5f28 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 25 Mar 2026 17:00:21 +0000
Subject: [PATCH 1/4] Initial plan
From 8d26d372bf36637d7e87059b773b79f054df79fd Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 25 Mar 2026 17:11:53 +0000
Subject: [PATCH 2/4] Fix vararg P/Invoke cross-assembly metadata lookup to use
m_pMetadataModule
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/4b003785-29cc-445b-9d52-64fa68ba9af2
---
src/coreclr/vm/dllimport.cpp | 2 +-
src/tests/Interop/Interop.csproj | 3 +-
.../CrossAssembly/CrossAssemblyVarargsTest.cs | 28 +++++++++++++++++++
.../VarArgsPInvokeLib/VarArgsPInvokeLib.cs | 14 ++++++++++
.../VarArgsPInvokeLib.csproj | 12 ++++++++
5 files changed, 57 insertions(+), 2 deletions(-)
create mode 100644 src/tests/Interop/PInvoke/Varargs/CrossAssembly/CrossAssemblyVarargsTest.cs
create mode 100644 src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
create mode 100644 src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp
index 68aec52fd682af..3939319fc80ede 100644
--- a/src/coreclr/vm/dllimport.cpp
+++ b/src/coreclr/vm/dllimport.cpp
@@ -4365,7 +4365,7 @@ static void CreatePInvokeStubAccessMetadata(
(*pNumArgs) = msig.NumFixedArgs();
- IMDInternalImport* pInternalImport = pSigDesc->m_pModule->GetMDImport();
+ IMDInternalImport* pInternalImport = pSigDesc->m_pMetadataModule->GetMDImport();
_ASSERTE(!SF_IsHRESULTSwapping(*pdwStubFlags));
diff --git a/src/tests/Interop/Interop.csproj b/src/tests/Interop/Interop.csproj
index b0762fcd2eeae9..ee10f9f8954ee2 100644
--- a/src/tests/Interop/Interop.csproj
+++ b/src/tests/Interop/Interop.csproj
@@ -12,6 +12,7 @@
+
@@ -42,7 +43,7 @@
-
+
diff --git a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/CrossAssemblyVarargsTest.cs b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/CrossAssemblyVarargsTest.cs
new file mode 100644
index 00000000000000..28a67968cbd7ee
--- /dev/null
+++ b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/CrossAssemblyVarargsTest.cs
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Text;
+using TestLibrary;
+using VarArgsPInvokeLib;
+using Xunit;
+
+namespace PInvokeTests
+{
+ public class CrossAssemblyVarargsTest
+ {
+ [ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsVarArgSupported))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
+ public static void TestCrossAssemblyVarArgs()
+ {
+ int arg1 = 10;
+ int arg2 = 20;
+ double arg3 = 12.5;
+ string expected = FormattableString.Invariant($"{arg1}, {arg2}, {arg3:F1}");
+
+ var builder = new StringBuilder(30);
+ VarArgsWrapper.TestVarArgs(builder, (IntPtr)30, "%i, %i, %.1f", __arglist(arg1, arg2, arg3));
+ Assert.Equal(expected, builder.ToString());
+ }
+ }
+}
diff --git a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
new file mode 100644
index 00000000000000..0451dc152ed002
--- /dev/null
+++ b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace VarArgsPInvokeLib
+{
+ public static class VarArgsWrapper
+ {
+ [DllImport("VarargsNative", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void TestVarArgs(StringBuilder builder, IntPtr bufferSize, string formatString, __arglist);
+ }
+}
diff --git a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
new file mode 100644
index 00000000000000..c10a86227913b9
--- /dev/null
+++ b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
@@ -0,0 +1,12 @@
+
+
+ Library
+ true
+
+
+
+
+
+
+
+
From 4b8ab8fc91b47b6a7a85ba677f463c9cfdba25f2 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 25 Mar 2026 17:32:01 +0000
Subject: [PATCH 3/4] Remove redundant CMakeProjectReference from
VarArgsPInvokeLib.csproj
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/44072add-6b71-4139-b896-eb1f86a283c9
---
.../CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
index c10a86227913b9..ff0035bf7259bc 100644
--- a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
+++ b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.csproj
@@ -6,7 +6,4 @@
-
-
-
From 84a6e16fee7330079cfe03590fea9672978486bb Mon Sep 17 00:00:00 2001
From: Jeremy Koritzinsky
Date: Thu, 23 Apr 2026 20:10:32 -0700
Subject: [PATCH 4/4] Update VarArgsPInvokeLib.cs
---
.../CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
index 0451dc152ed002..f5ccf0b037c0f3 100644
--- a/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
+++ b/src/tests/Interop/PInvoke/Varargs/CrossAssembly/VarArgsPInvokeLib/VarArgsPInvokeLib.cs
@@ -9,6 +9,6 @@ namespace VarArgsPInvokeLib
public static class VarArgsWrapper
{
[DllImport("VarargsNative", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
- public static extern void TestVarArgs(StringBuilder builder, IntPtr bufferSize, string formatString, __arglist);
+ public static extern void TestVarArgs(StringBuilder builder, nint bufferSize, string formatString, __arglist);
}
}