One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?

I am trying to compile this code in Microsoft Visual C# 2010

using System;
using System.Globalization;


class main
{
    static void Main()
    {

        dynamic d;
        d = "dyna";
        Console.WriteLine(d);    
    }
}

but I am getting these two errors

Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported

Error 2 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?

I read this other post but I am new to C# and I couldn't understand what really is the problem. Especially what and where are these so called .config files..


Solution 1:

On your solution explorer window, right click to References, select Add Reference, go to .NET tab, find and add Microsoft.CSharp.

Alternatively add the Microsoft.CSharp NuGet package.

Install-Package Microsoft.CSharp

Solution 2:

Make sure that your project is targeting the .NET framework 4.0. Visual Studio 2010 supports .NET 3.5 framework target also, but .NET 3.5 does not support the dynamic keyword.

You can adjust the framework version in the project properties. See http://msdn.microsoft.com/en-us/library/bb398202.aspx for more info.