Dynamic in the immediate window causes 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported error
Solution 1
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
Two things are important. Check the following:
- 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))
- 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
- Go to project->add reference.
- select assemblies from the side bar and Framework
- check Microsoft.CSharp
Happy coding!
Solution 4
Namespace: Microsoft.CSharp.RuntimeBinder
Assembly: Microsoft.CSharp (in Microsoft.CSharp.dll)
http://msdn.microsoft.com/en-us/library/microsoft.csharp.runtimebinder.binder%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/microsoft.csharp.runtimebinder%28v=vs.110%29.aspx
Colonel Panic
If you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that's really the essence of programming. By the time you've sorted out a complicated idea into little steps that even a stupid machine can deal with, you've learned something about it yourself. —Douglas Adams
Updated on July 05, 2022Comments
-
Colonel Panic almost 2 years
If I use
dynamic
in the immediate window of Visual Studio I get an errorPredefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported
How can I fix that?
-
Colonel Panic over 11 yearsHow do I do that? I'm using the 'immediate window'
-
HoberMellow over 11 yearsYou use immediate window in environment of some project. You should add reference to this project.
-
Snixtor over 11 yearsThis is applicable also to debug watch windows. I had a solution with a startup project that did not reference Microsoft.CSharp, but referenced another project that did. Watch windows would throw the "binder not defined or imported" exception. Added a reference to Microsoft.CSharp on the startup project and all was well.
-
Louis Somers almost 11 yearsReferencing it in the currently selected project does not seem to work. I am having the same issue with System.Data, which is referenced, but cannot be found by the immediate window. Probably that only works during a debugging session? I'm using it to call a static method without starting a debugging session.
-
Victor Michael Kosgei about 9 yearsdont forget to click Ok
-
Lazy Coder about 7 yearsUp voted, was hung up on unit test project not having that "Microsoft.CSharp" assembly referenced