Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mono runtime doesn't check modreqs for overriding methods #6936

@OmarTawfik

Description

@OmarTawfik

If a virtual method has a modreq on one of the parameters, but a child type overrides this method without having the modreq, the CLR considers them two different signatures, and they don't override each other, which leads to the following behavior:

Signature of the virtual Parent.M(in int):

.method public hidebysig newslot virtual instance string M ([in] int32& modreq([mscorlib]System.Runtime.InteropServices.InAttribute) x) cil managed

Signature of the overriding Child.M(in int):

.method public hidebysig virtual instance string M ([in] int32& x) cil managed

User code:

namespace clrbug
{
    class Program
    {
        static void Main(string[] args)
        {
            Test(new Parent());
            Test(new Child());
        }
        static void Test(Parent obj)
        {
            Console.WriteLine(obj.M(0));
        }
    }
}

On CoreCLR:

dotnet clrbug.dll
Parent
Parent

On Mono:

mono clrbug.dll
Parent
Child

Here are the two binaries, the one that has that IL, and the console application: monobug.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions