Dynamic in the immediate window causes 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported error

C#.NetVisual StudioDynamicImmediate Window

C# Problem Overview


If I use dynamic in the immediate window of Visual Studio I get an error

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

How can I fix that?

C# Solutions


Solution 1 - C#

You should add reference to Microsoft.CSharp library in the selected project or in the startup project. And your project should reference .NET Framework 4 or higher.

MSDN about immediate window context:

> When establishing the context for design time expression evaluation, > Visual Studio references the currently selected project in Solution > Explorer. If no project is selected in Solution Explorer, Visual > Studio attempts to evaluate the function against the startup project. > If the function cannot be evaluated in the current context, you will > receive an error message.

Solution 2 - C#

Two things are important. Check the following:

  1. That your project properties are referencing .NET Framework 4 or higher (if that is not the case, change it: Right click on the project, select the "Properties..." menu item, then select as target framework ".NET Framework 4" (or higher))
  2. That you have added the "Microsoft.CSharp" assembly as reference (note that step 1., which requires to re-load the project, must be done before you can do that)

Afterwards you can use the dynamic type. The reference needs to be added in the selected project or in the startup project in order to become available in the immediate window's scope.


Note: Here I found a nice article about dynamics in C#, how it works and what you can do with it.

Solution 3 - C#

  1. Go to project->add reference.
  2. select assemblies from the side bar and Framework
  3. check Microsoft.CSharp

Happy coding!

Solution 4 - C#

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionColonel PanicView Question on Stackoverflow
Solution 1 - C#HoberMellowView Answer on Stackoverflow
Solution 2 - C#MattView Answer on Stackoverflow
Solution 3 - C#Victor Michael KosgeiView Answer on Stackoverflow
Solution 4 - C#Ahmed GalalView Answer on Stackoverflow