简体   繁体   English

立即窗口中的动态导致'Microsoft.CSharp.RuntimeBinder.Binder'未定义或导入错误

[英]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: 检查以下内容:

  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)) 您的项目属性引用.NET Framework 4或更高版本 (如果不是这样,请更改它:右键单击项目,选择“Properties ...”菜单项,然后选择作为目标框架“.NET Framework 4 “ (或更高))
  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) 您已添加“Microsoft.CSharp”程序集作为参考(请注意,步骤1,需要重新加载项目,必须先完成,然后才能执行此操作)

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#中的动态 ,它如何工作以及你可以用它做什么的好文章。

  1. Go to project->add reference. 转到项目 - >添加引用。
  2. select assemblies from the side bar and Framework 从侧栏和框架中选择装配
  3. check Microsoft.CSharp 检查Microsoft.CSharp

Happy coding! 快乐的编码!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 缺少类型Microsoft.CSharp.RuntimeBinder.Binder - Missing type Microsoft.CSharp.RuntimeBinder.Binder 未定义或导入预定义类型microsoft.csharp.runtimebinder - Predefined type microsoft.csharp.runtimebinder is not defined or imported 缺少编译器所需的成员“microsoft.csharp.runtimebinder.binder.convert” - Missing compiler required member 'microsoft.csharp.runtimebinder.binder.convert' Microsoft.CSharp.RuntimeBinder.RuntimeBinderException错误 - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException Error 在私有类型上动态抛出Microsoft.CSharp.RuntimeBinder.RuntimeBinderException - Dynamic throwing Microsoft.CSharp.RuntimeBinder.RuntimeBinderException on private types 在 C# 中嵌入 IronPython 的问题(缺少编译器所需的成员“Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember” - Problems embedding IronPython in C# (Missing Compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember' ASP.Net CORE 3.1 - 抛出错误异常:Microsoft.CSharp.dll 中的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException” - ASP .Net CORE 3.1 - Error Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll 发生``Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'' - 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred 访问动态属性会引发“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的异常 - Accessing a dynamic's property threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' #SpecFlow# For CreateDynamicInstance() - 错误 - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:最佳重载方法 - #SpecFlow# For CreateDynamicInstance() - error - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : The best overloaded method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM