This project is read-only.
2

Resolved

Null-propagation operator on dynamic variable causes AccessViolationException

description

Applying .? operator to dynamic variable causes the application to throw AccessViolatonException:
class SomeType
{
    public object SomeProperty { get; set; }

    static void Main()
    {
        var obj = new SomeType() { SomeProperty = "ABCD" };

        var p1 = ((dynamic)obj).SomeProperty;   //OK, p1 is set to "ABCD"
        var p2 = ((dynamic)obj)?.SomeProperty;  //AccessViolationException

        Console.ReadLine();
    }
}
System: Windows 8

Examination of built assembly with PEVerify shows:
[IL]: Error: [C:\Debug\ConsoleApplication7.exe : ConsoleApplication7.SomeType::Main][offset 0x000000B2][found ref 'System.Func3[System.Runtime.CompilerServices.CallSite,System.Object,System.Object]'][expected ref 'System.Runtime.CompilerServices.CallSite'] Unexpected type on the stack.
[IL]: Error: [C:\Debug\ConsoleApplication7.exe : ConsoleApplication7.SomeType::Main][offset 0x000000B2][found ref 'ConsoleApplication7.SomeType'][expected ref 'System.Func
3[System.Runtime.CompilerServices.CallSite,System.Object,System.Object]'] Unexpected type on the stack.