This project is read-only.
2

Resolved

Indexer initiaizers are not represented correctly in expression trees

description

Compile and run:
using System;
using System.Collections;
using System.Linq.Expressions;

class C
{
    static void Main()
    {
        Expression<Func<C>> e = () => new C { H = { ["Key"] = "Value" } };
        Console.WriteLine(e);
        var c = e.Compile().Invoke();
        Console.WriteLine(c.H["Key"]);        
    }

    readonly Hashtable H = new Hashtable();
}
ACTUAL:
No compile-time errors.
() => new C() {H = {Item = "Value"}}

Unhandled Exception: System.Security.VerificationException: Operation could destabilize the runtime.
   at lambda_method(Closure )
   at C.Main() in \ConsoleApplication8\Program.cs:line 11
EXPECTED:
A compile-time error.
OR
A correct expression tree that can be successfully compiled and invoked.

comments

angocke wrote Aug 15, 2014 at 1:12 AM

Fixed in changeset bb4a724bb8e755183e72da36ebad20cc93fc957f