44

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. Commented Sep 2, 2016 at 21:37

3 Answers 3

65

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
Microsoft.CSharp depends on System.Dynamic.Runtime, so you don't need to add both.
@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?
32

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

1 Comment

This fixed my issue. I am running .net core 2.1 (or 2.2... same issue). I only needed to add Microsoft.CSharp.
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 Comments

Is there an authoritative reference for which "frameworks" should be used for which purposes? I've been looking for information on what all this means, and all I find are contradictory blogs and similar. What's your source for this information?
For a start, that's what the project.json produced by dotnet new -t console and dotnet new -t lib produce. For more explanation, see the article Packages, Metapackages and Frameworks in .Net docs, specifically the section on Package-based Frameworks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.