简体   繁体   English

ASP.NET Core 1.1 使用 C# 动态编译 缺少编译器需要成员 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

[英]ASP.NET Core 1.1 compiling with C# dynamic Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

I'm using Visual Studio 2017 RC and started a new ASP.NET Core project targeting the full .NET Framework.我正在使用 Visual Studio 2017 RC 并启动了一个新的 ASP.NET 核心项目,目标是完整的 .NET 框架。

This line of code will not compile.这行代码不会编译。

 dynamic handler = _container.GetService(handlerType);

 if (handler == null) _logger.LogError("Can't find handler to handle " + cmd.GetType().Name);

I get the following error我收到以下错误

CS0656  Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

After some Googling it looks like this is because I'm missing the Microsoft.CSharp Assembly.经过一些谷歌搜索后,它看起来是因为我缺少 Microsoft.CSharp 程序集。 There are plenty of people who have stumbled into his issue but not seemingly with .NET Core 1.1.有很多人偶然发现了他的问题,但似乎不是 .NET Core 1.1。

So I did this Install-Package Microsoft.CSharp and got version 4.3.0.所以我做了这个Install-Package Microsoft.CSharp并获得了 4.3.0 版。 My project still won't build.我的项目仍然无法构建。

If I add an Assembly Reference to Microsoft.CSharp (the GAC'd version) then it Compiles and runs.如果我将程序集引用添加到 Microsoft.CSharp(GAC 版本),那么它会编译并运行。

Is this a Bug?这是一个错误吗? I would have expected the NuGet package to fix this?我本来希望 NuGet package 能解决这个问题?

只需添加 Microsoft.CSharp.dll 的引用,您的错误将被删除。

I faced this problem.我遇到了这个问题。 I resolved this problem for me.我为我解决了这个问题。 You must install Microsoft.CSharp library to your solution from nuget.您必须从 nuget 将Microsoft.CSharp库安装到您的解决方案中。

You can use Package Manager Console for install Microsoft.CSharp .您可以使用包管理器控制台安装Microsoft.CSharp For example If you want install Microsoft.CSharp 4.7.0 version, you must run this command on the Package Manager Console:例如,如果要安装 Microsoft.CSharp 4.7.0 版本,则必须在包管理器控制台上运行此命令:

Install-Package Microsoft.CSharp -Version 4.7.0

Nuget link: Microsoft.CSharp Nuget 链接: Microsoft.CSharp

There was a similar problem.有一个类似的问题。 I wanted to create a NetStandartd 2.0 library for the NetFramework 4.6.2 environment that uses a dynamic object and got the error "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create".我想为uses a dynamic object的 NetFramework 4.6.2 环境创建一个 NetStandartd 2.0 库,但出现错误“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create”。 This error is caused by the absence of the Microsoft.CSharp library .此错误是由于缺少of the Microsoft.CSharp library引起的。 By correcting.csproj file I was able to make the correct linking :通过correcting.csproj文件,我能够to make the correct linking

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0;net462</TargetFramework>
    <DependsOnNETStandard>netstandard2.0</DependsOnNETStandard>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
</Project>

I was getting this problem when trying to implicitly casting type dynamic<\/code> to object<\/code> .我在尝试将类型dynamic<\/code>隐式转换为object<\/code>时遇到了这个问题。

    var output = new Dictionary<string, object>(); // <- object
    foreach(var attribute in attributes)
    {
        var attr = attribute as IEntityAttribute<dynamic>; // <- dynamic
        if (attr != null)
        {
            output.Add(attr.GetType().Name, attr.Value);
        }
    }
    return output;

暂无
暂无

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

相关问题 如何修复“错误 CS0656:缺少编译器所需的成员‘Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’” - How to fix "error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'" 在 C# 中嵌入 IronPython 的问题(缺少编译器所需的成员“Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember” - Problems embedding IronPython in C# (Missing Compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember' 缺少编译器所需的成员“microsoft.csharp.runtimebinder.binder.convert” - Missing compiler required member 'microsoft.csharp.runtimebinder.binder.convert' 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.Binder - Missing type Microsoft.CSharp.RuntimeBinder.Binder 缺少编译器所需的成员,但已添加 Microsoft.CSharp package - Missing compiler required member but have already added Microsoft.CSharp package 定期看到ASP.NET错误CS0656:缺少编译器所需的成员 - Periodically seeing the ASP.NET error CS0656: Missing compiler required member C# Roslyn .NET CORE 3.1 CSharpCompilation 动态 RuntimeBinder.Binder.Convert 错误 - C# Roslyn .NET CORE 3.1 CSharpCompilation dynamic RuntimeBinder.Binder.Convert Error C# ASP.NET 核心 MVC 需要 object 参考 - C# ASP.NET Core MVC An object reference is required 在私有类型上动态抛出Microsoft.CSharp.RuntimeBinder.RuntimeBinderException - Dynamic throwing Microsoft.CSharp.RuntimeBinder.RuntimeBinderException on private types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM