I am trying to compile this code in Microsoft Visual C# 2010 我正在尝试在Microsoft Visual C#2010中编译此代码
using System;
using System.Globalization;
class main
{
static void Main()
{
dynamic d;
d = "dyna";
Console.WriteLine(d);
}
}
but I am getting these two errors 但是我遇到了这两个错误
Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported 错误1未定义或导入预定义的类型'Microsoft.CSharp.RuntimeBinder.Binder'
Error 2 One or more types required to compile a dynamic expression cannot be found. 错误2找不到编译动态表达式所需的一种或多种类型。 Are you missing references to Microsoft.CSharp.dll and System.Core.dll? 您是否缺少对Microsoft.CSharp.dll和System.Core.dll的引用?
I read this other post but I am new to C# and I couldn't understand what really is the problem. 我读了另一篇文章,但是我是C#的新手,我不明白真正的问题是什么。 Especially what and where are these so called .config
files.. 特别是这些所谓的.config
文件在什么地方。
#1楼
#2楼
在您的解决方案资源管理器窗口中,右键单击“引用”,选择“添加引用”,转到“ .NET”选项卡,找到并添加Microsoft.CSharp。
#3楼
Make sure that your project is targeting the .NET framework 4.0. 确保您的项目面向.NET Framework 4.0。 Visual Studio 2010 supports .NET 3.5 framework target also, but .NET 3.5 does not support the dynamic
keyword. Visual Studio 2010也支持.NET 3.5框架目标,但是.NET 3.5不支持dynamic
关键字。
You can adjust the framework version in the project properties. 您可以在项目属性中调整框架版本。 See http://msdn.microsoft.com/en-us/library/bb398202.aspx for more info. 有关更多信息,请参见http://msdn.microsoft.com/zh-cn/library/bb398202.aspx 。
#4楼
Red lines under the ViewBag was my headache for 3 month ). ViewBag下的红线让我头痛了3个月)。 Just remove the Microsoft.CSharp reference from project and then add it again. 只需从项目中删除Microsoft.CSharp引用,然后再次添加即可。
#5楼
我遇到了同样的问题,并通过从项目中删除“ Microsoft.CSharp”引用来解决它,然后再次添加了它。
#6楼
I had the same issue except removing and adding the reference back did not fix the error, so I changed .Net version from 4.5
to 4.5.1
. 除了删除并添加回引用不能解决错误之外,我遇到了相同的问题,因此我将.Net版本从4.5
更改为4.5.1
。
To achieve this go to your web.config
file and change the following lines 为此,请转到您的web.config
文件并更改以下几行
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
to this 对此
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
and rebuild. 并重建。