简体   繁体   中英

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.

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. There are plenty of people who have stumbled into his issue but not seemingly with .NET Core 1.1.

So I did this Install-Package Microsoft.CSharp and got version 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.

Is this a Bug? I would have expected the NuGet package to fix this?

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

I faced this problem. I resolved this problem for me. You must install Microsoft.CSharp library to your solution from nuget.

You can use Package Manager Console for install Microsoft.CSharp . For example If you want install Microsoft.CSharp 4.7.0 version, you must run this command on the Package Manager Console:

Install-Package Microsoft.CSharp -Version 4.7.0

Nuget link: 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". This error is caused by the absence of the Microsoft.CSharp library . By correcting.csproj file I was able 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> .

    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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM