找不到编译动态表达式所需的一种或多种类型。 您是否缺少对Microsoft.CSharp.dll和System.Core.dll的引用?

在使用C#编译动态表达式时遇到错误,提示缺少Microsoft.CSharp.dll和System.Core.dll的引用。解决方案包括检查项目是否引用这两个DLL,确保目标框架为.NET 4.0,删除并重新添加Microsoft.CSharp引用,以及检查.csproj文件中的.NET版本设置。
摘要由CSDN通过智能技术生成

本文翻译自:One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?

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楼

参考:https://stackoom.com/question/Nclc/找不到编译动态表达式所需的一种或多种类型-您是否缺少对Microsoft-CSharp-dll和System-Core-dll的引用


#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. 并重建。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值