[英]Dynamic in the immediate window causes 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported error
If I use dynamic
in the immediate window of Visual Studio I get an error 如果我在Visual Studio的即时窗口中使用
dynamic
,我会收到错误
Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported
未定义或导入预定义类型“Microsoft.CSharp.RuntimeBinder.Binder”
How can I fix that? 我该如何解决这个问题?
You should add reference to Microsoft.CSharp library in the selected project or in the startup project. 您应该在所选项目或启动项目中添加对Microsoft.CSharp库的引用。 And your project should reference .NET Framework 4 or higher.
您的项目应该引用.NET Framework 4或更高版本。
MSDN about immediate window context: 关于即时窗口上下文的MSDN:
When establishing the context for design time expression evaluation, Visual Studio references the currently selected project in Solution Explorer.
在为设计时表达式评估建立上下文时,Visual Studio将在Solution Explorer中引用当前选定的项目。 If no project is selected in Solution Explorer, Visual Studio attempts to evaluate the function against the startup project.
如果在解决方案资源管理器中未选择任何项目,Visual Studio将尝试针对启动项目评估该功能。 If the function cannot be evaluated in the current context, you will receive an error message.
如果无法在当前上下文中评估该函数,您将收到一条错误消息。
Two things are important. 有两件事很重要。 Check the following:
检查以下内容:
Afterwards you can use the dynamic
type. 之后您可以使用
dynamic
类型。 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. 注意: 在这里,我发现了一篇关于C#中的动态 ,它如何工作以及你可以用它做什么的好文章。
Happy coding! 快乐的编码!
Namespace: Microsoft.CSharp.RuntimeBinder 命名空间:Microsoft.CSharp.RuntimeBinder
Assembly: Microsoft.CSharp (in Microsoft.CSharp.dll) 程序集:Microsoft.CSharp(在Microsoft.CSharp.dll中)
Example 例
http://stepbystepdotnet.wordpress.com/2012/08/06/predefined-type-microsoft-csharp-runtimebinder-binder-is-not-defined-or-importedtestproject1/ http://stepbystepdotnet.wordpress.com/2012/08/06/predefined-type-microsoft-csharp-runtimebinder-binder-is-not-defined-or-importedtestproject1/
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.