Skip to content

Instantly share code, notes, and snippets.

@lambdageek
Last active February 22, 2019 21:24
Show Gist options
  • Select an option

  • Save lambdageek/cdb2b5ea69bcce3debce410b03a7e601 to your computer and use it in GitHub Desktop.

Select an option

Save lambdageek/cdb2b5ea69bcce3debce410b03a7e601 to your computer and use it in GitHub Desktop.

compile with

~/work/roslyn/roslyn/Binaries/Tools/ILAsm/ilasm -DLL  modmod.il
csc test.cs -r:modmod.dll

run with

ALEKSEY_HACK=1 mono test.exe

expected output is: Test Overridden

actual output is:

Unhandled Exception:
System.MissingMethodException: Method not found: void .CL1`1.Test(!0 modopt(System.Nullable`1<!0>))
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: void .CL1`1.Test(!0 modopt(System.Nullable`1<!0>))

This is extracted from ModifiersWithConstructedType_01 from Roslyn https://github.com/dotnet/roslyn/blob/306e21276ac0b6e305c58a06187188d03057050b/src/Compilers/CSharp/Test/Symbol/Symbols/CustomModifiersTests.cs#L2044

.assembly extern mscorlib { }
.assembly ModMod { }
.class public auto ansi beforefieldinit CL1`1<valuetype .ctor ([mscorlib]System.ValueType) T1>
extends[mscorlib] System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: call instance void[mscorlib] System.Object::.ctor()
IL_0006:
ret
} // end of method CL1`1::.ctor
.method public hidebysig newslot virtual
instance void Test(!T1 modopt(valuetype [mscorlib]System.Nullable`1<!T1>) t1) cil managed
{
// Code size 1 (0x1)
.maxstack 1
IL_0000: ldstr "Test"
IL_0005: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ret
} // end of method CL1`1::Test
} // end of class CL1`1
.class public auto ansi beforefieldinit CL2
extends class CL1`1<int32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong)>
{
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: call instance void class CL1`1<int32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong)>::.ctor()
IL_0006: ret
} // end of method CL2::.ctor
} // end of class CL2
class Test
{
static void Main()
{
var x = new CL2();
x.Test(1);
x = new CL3();
x.Test(1);
}
}
class CL3 : CL2
{
public override void Test(int c)
{
System.Console.WriteLine("Overridden");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment