diff --git a/Mono.Cecil/MetadataResolver.cs b/Mono.Cecil/MetadataResolver.cs index 6511b4187..95d900726 100644 --- a/Mono.Cecil/MetadataResolver.cs +++ b/Mono.Cecil/MetadataResolver.cs @@ -264,6 +264,9 @@ public static MethodDefinition GetMethod (Collection methods, if (!AreSame (method.ReturnType, reference.ReturnType)) continue; + if (method.HasThis != reference.HasThis) + continue; + if (method.IsVarArg () != reference.IsVarArg ()) continue; diff --git a/Test/Mono.Cecil.Tests/MethodTests.cs b/Test/Mono.Cecil.Tests/MethodTests.cs index b878613c0..cef897dd2 100644 --- a/Test/Mono.Cecil.Tests/MethodTests.cs +++ b/Test/Mono.Cecil.Tests/MethodTests.cs @@ -221,5 +221,20 @@ public void ReturnParameterMethod () Assert.IsNotNull (method); Assert.AreEqual (method, method.MethodReturnType.Parameter.Method); } + + [Test] + public void InstanceAndStaticMethodComparison () + { + TestIL ("others.il", module => { + var others = module.GetType ("Others"); + var instance_method = others.Methods.Single (m => m.Name == "SameMethodNameInstanceStatic" && m.HasThis); + var static_method_reference = new MethodReference ("SameMethodNameInstanceStatic", instance_method.ReturnType, others) + { + HasThis = false + }; + + Assert.AreNotEqual(instance_method, static_method_reference.Resolve ()); + }); + } } } diff --git a/Test/Resources/il/others.il b/Test/Resources/il/others.il index 60713af30..22691a2d2 100644 --- a/Test/Resources/il/others.il +++ b/Test/Resources/il/others.il @@ -78,4 +78,14 @@ .other instance void Others::dang_Handler (class [mscorlib]System.EventHandler) .other instance void Others::fang_Handler (class [mscorlib]System.EventHandler) } + + .method public instance void SameMethodNameInstanceStatic() cil managed + { + ret + } + + .method public static void SameMethodNameInstanceStatic() cil managed + { + ret + } // end of static method MethodNameTests::MethodName }