Using System.Dynamic in Roslyn on coreclr
<p>I have a similar issue to the problem raised here <a href="https://stackoverflow.com/questions/22864790/using-system-dynamic-in-roslyn">Using System.Dynamic in Roslyn</a> </p>

<p>When attempting to compile code with roslyn using dynamic objects I receive a compiler error:</p>

<pre><code>CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.SetMember'
</code></pre>

<p>I have the reference to Microsoft.CSharp added.  The problem only occurs when running on coreclr, it works perfectly on the full framework.</p>

<p>A full example is:</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Reflection;
using System.Reflection.Metadata;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

public class Program
{
    public static void Main(string[] args)
    {
        var text = @"using System.Dynamic;

        public class Calculator
        {
            public static object Evaluate()
            {
                dynamic x = new ExpandoObject();
                x.Result = 42;
                return x.Result;
            } 
        }";

        var references = new List&lt;MetadataReference&gt;();

#if DNXCORE50
        // reference system.runtime
        references.Add(GetMetadataReference(typeof(object).GetTypeInfo().Assembly));
        // reference system.dynamic.runtime
        references.Add(GetMetadataReference(typeof(ExpandoObject).GetTypeInfo().Assembly));
        // reference microsoft.csharp
        references.Add(GetMetadataReference(typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).GetTypeInfo().Assembly));     
#elif DNX451
        references.Add(MetadataReference.CreateFromFile(typeof(object).Assembly.Location));
        references.Add(MetadataReference.CreateFromFile(typeof(ExpandoObject).Assembly.Location));
        references.Add(MetadataReference.CreateFromFile(typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.Location));
#endif

        var tree = SyntaxFactory.ParseSyntaxTree(text);

        var compilation = CSharpCompilation.Create(
            "calc.dll",
            options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
            syntaxTrees: new[] { tree },
            references: references);

        using (var stream = new MemoryStream())
        {
            var compileResult = compilation.Emit(stream);

            if (!compileResult.Success)
            {
                // fails here when running on coreclr
                throw new Exception(compileResult.Diagnostics[0].ToString());
            }
        }
    }

    public static unsafe MetadataReference GetMetadataReference(Assembly assembly)
    {
        byte* b;
        int length;

        MetadataReference reference = null;
        if (assembly.TryGetRawMetadata(out b, out length))
        {
            var moduleMetadata = ModuleMetadata.CreateFromMetadata((IntPtr)b, length);
            var assemblyMetadata = AssemblyMetadata.Create(moduleMetadata);
            reference = assemblyMetadata.GetReference();
        }

        return reference;
    }
}
</code></pre>

<p>I used the technique described here <a href="http://www.strathweb.com/2016/03/roslyn-scripting-on-coreclr-net-cli-and-dnx-and-in-memory-assemblies/" rel="nofollow noreferrer">http://www.strathweb.com/2016/03/roslyn-scripting-on-coreclr-net-cli-and-dnx-and-in-memory-assemblies/</a> to obtain the metadata references to the in memory assemblies as Assembly.Location is null for coreclr.</p>

<p>The project.json file:</p>

<pre><code>{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "steve" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "compilationOptions": {
    "emitEntryPoint": true,
    "allowUnsafe": true
  },

  "dependencies": {
    "Microsoft.CodeAnalysis.Common": "1.1.0-rc1-20151109-01",
    "Microsoft.CodeAnalysis.CSharp": "1.1.0-rc1-20151109-01",
    "System.Runtime.Loader": "4.0.0-beta-23516"
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Threading.Tasks": "4.0.0.0",
        "System.Text.Encoding": "4.0.0.0",
        "System.IO": "4.0.0.0",
        "System.Reflection": "4.0.0.0"
      }
    },
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Console": "4.0.0-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}
</code></pre>

<p>I've tried this on 1.0.0-rc1-update1 and update2 and tried adding references to other assemblies but cannot figure out why it fails.  </p>

<p>Any ideas out there?</p>