43

I'm trying to use a dynamic variable in a C# .net core app that's targeting .net standard 1.6. (platform? library? framework? meta-framework?) I first encountered this problem in a real application, but I have reduced it to a minimal reproduction.

project.json

{
    "version": "1.0.0-*",
    "buildOptions": { "emitEntryPoint": true },
    "dependencies": { "NETStandard.Library": "1.6.0" },
    "frameworks": {
        "netstandard1.6": { "imports": "dnxcore50" }
    },
    "runtimes": { "win10-x64": {} }
}

Program.cs

using System;

public class Program {
    public static void Main(string[] args) {
        dynamic hello = "hello world";
        Console.WriteLine(hello);
    }
}

When I try to build this, I'm getting a build error on Console.WriteLine(hello); saying this.

CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

Is it possible to use dynamic variables in an application targeting netstandard 1.6? How?

1
  • If it helps, targeting netcoreapp1.0 (that's also supporting netstandard 1.6) fixes the error. That's weird. Sep 2, 2016 at 21:37

3 Answers 3

64

Add System.Dynamic.Runtime and Microsoft.CSharp as dependencies.

3
  • 3
    I ended up having to add the following dependencies and versions: "System.Dynamic.Runtime": "4.0.11", "Microsoft.CSharp": "4.0.1", "Microsoft.NETCore.Runtime.CoreCLR": "1.0.4". It's able to build and run now.
    – recursive
    Sep 2, 2016 at 21:52
  • 7
    Microsoft.CSharp depends on System.Dynamic.Runtime, so you don't need to add both.
    – svick
    Sep 3, 2016 at 9:45
  • 3
    @recursive: I concur. I had to add all three of these as well. Maybe it has something to do with the fact that it's a .NET Standard project? Nov 21, 2017 at 20:40
32

Right-click the project > Manage NuGet Packages... > Add the following two highlighted packages: enter image description here

1
  • This fixed my issue. I am running .net core 2.1 (or 2.2... same issue). I only needed to add Microsoft.CSharp.
    – ebol2000
    May 24, 2019 at 20:42
7

If you're writing an application, not a library, you should use Microsoft.NETCore.App, not NETStandard.Library and netcoreapp1.0, not netstandard1.6. Doing that would fix your issue.

If you want to use dynamic in a library (or application that does not depend on Microsoft.NETCore.App), you need to add Microsoft.CSharp as a dependency.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.