From 53d01869c97c8a89589882a8ef8852fe5b9f216a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schm=C3=B6cker?= Date: Sat, 5 Jul 2025 16:48:58 +0200 Subject: [PATCH 1/2] Fix incorrect method for static methods with instance signature --- ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs b/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs index bc7ff1bb4..ec0cdca4e 100644 --- a/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs +++ b/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs @@ -535,6 +535,8 @@ namespace ICSharpCode.Decompiler.TypeSystem { if (m.TypeParameters.Count != signature.GenericParameterCount) continue; + if (signature.Header.IsInstance != !m.IsStatic) + continue; if (CompareSignatures(m.Parameters, parameterTypes) && CompareTypes(m.ReturnType, signature.ReturnType)) { method = m; From cc4588db4b6674f56364bc54298fdede0a3ed17a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 5 Jul 2025 19:06:46 +0200 Subject: [PATCH 2/2] Add a test case --- .../ICSharpCode.Decompiler.Tests.csproj | 2 ++ .../ILPrettyTestRunner.cs | 6 ++++ .../TestCases/ILPretty/Issue3504.cs | 9 +++++ .../TestCases/ILPretty/Issue3504.il | 36 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index d581a3ffd..50bc5be58 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -96,6 +96,7 @@ + @@ -138,6 +139,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index abdc031fa..57fa18c7c 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -225,6 +225,12 @@ namespace ICSharpCode.Decompiler.Tests await Run(); } + [Test] + public async Task Issue3504() + { + await Run(); + } + [Test] public async Task Issue2260SwitchString() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.cs new file mode 100644 index 000000000..c5d8238f0 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.cs @@ -0,0 +1,9 @@ +using System; + +internal class Issue3504 +{ + private void Method(Console console) + { + console.WriteLine("Hello."); + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.il new file mode 100644 index 000000000..6637e6f9e --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue3504.il @@ -0,0 +1,36 @@ +.class private auto ansi beforefieldinit Issue3504 + extends [System.Runtime]System.Object +{ + // Methods + .method private hidebysig + instance void Method (class [System.Console]System.Console console) cil managed + { + // Method begins at RVA 0x2050 + // Header size: 1 + // Code size: 13 (0xd) + .maxstack 8 + + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldstr "Hello." + IL_0007: call instance void [System.Console]System.Console::WriteLine(string) + IL_000b: nop + IL_000c: ret + } // end of method Issue3504::Method + + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x205e + // Header size: 1 + // Code size: 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [System.Runtime]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method Issue3504::.ctor + +} // end of class Issue3504 +