C# 即时窗口中的动态导致'Microsoft.CSharp.RuntimeBinder.Binder'未定义或导入错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13566887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dynamic in the immediate window causes 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported error
提问by Colonel Panic
If I use dynamicin the immediate window of Visual Studio I get an error
如果我dynamic在 Visual Studio 的直接窗口中使用,则会出现错误
Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported
未定义或导入预定义类型“Microsoft.CSharp.RuntimeBinder.Binder”
How can I fix that?
我该如何解决?
采纳答案by HoberMellow
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.
您应该在所选项目或启动项目中添加对 Microsoft.CSharp 库的引用。并且您的项目应引用 .NET Framework 4 或更高版本。
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.
在为设计时表达式评估建立上下文时,Visual Studio 会引用解决方案资源管理器中当前选定的项目。如果在解决方案资源管理器中未选择任何项目,Visual Studio 将尝试针对启动项目评估该函数。如果无法在当前上下文中评估该函数,您将收到一条错误消息。
回答by Matt
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" assemblyas reference (note that step 1., which requires to re-load the project, must be done before you can do that)
- 您的项目属性引用.NET Framework 4 或更高版本(如果不是这种情况,请更改它:右键单击项目,选择“属性...”菜单项,然后选择“.NET Framework 4”作为目标框架“ (或更高))
- 您已添加“Microsoft.CSharp”程序集作为参考(请注意,必须先完成需要重新加载项目的步骤 1.)
Afterwards you can use the dynamictype. 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.
之后您可以使用该dynamic类型。需要将引用添加到所选项目或启动项目中,以便在直接窗口的范围内可用。
Note:HereI found a nice article about dynamicsin C#, how it works and what you can do with it.
注意:在这里我找到了一篇关于C# 中的动力学的好文章,它是如何工作的以及你可以用它做什么。
回答by Ahmed Galal
Namespace: Microsoft.CSharp.RuntimeBinder
命名空间:Microsoft.CSharp.RuntimeBinder
Assembly: Microsoft.CSharp (in Microsoft.CSharp.dll)
程序集:Microsoft.CSharp(在 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.binder%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/microsoft.csharp.runtimebinder%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/microsoft.csharp.runtimebinder%28v=vs.110%29.aspx
回答by Victor Michael Kosgei
- Go to project->add reference.
- select assemblies from the side bar and Framework
- check Microsoft.CSharp
- 转到项目-> 添加引用。
- 从侧栏和框架中选择程序集
- 检查 Microsoft.CSharp
Happy coding!
快乐编码!

