无法构建C#项目

时间:2015-09-09 08:49:37

标签: c# .net json dynamic


我有一些奇怪的问题。
使用此代码时,我无法构建,但它没有给我构建错误。

代码

public void myMethod()
{              
    //This returns a string in JSON format.
    var jsonResponse = myApi.ReadMobileDevice("1");


    dynamic dynamicJson= JsonConvert.DeserializeObject(jsonResponse);

    //THIS LINE BREAKS MY BUILD. NO BUILD ERRORS SHOWN
    var jValue = dynamicJson["general.display_name"];
}

有谁能告诉我为什么我的构建制动,以及为什么没有显示构建错误?

更新 - 输出
*还将var更改为字符串

1>------ Build started: Project: Control, Configuration: Debug x86 ------
1>  Restoring NuGet packages...
1>  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages'.
1>  All packages listed in packages.config are already installed.
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(563,28,563,40): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
1>C:\ActacomProjects\DEV-Google\Control\Classes\DomainObjects\Schedules\HTTPSchedulesResponse.cs(41,34,41,36): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\Classes\DomainObjects\Schedules\HTTPSchedulesResponse.cs(87,30,87,32): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(1225,26,1225,45): warning CS0219: The variable 'recreateApplication' is assigned but its value is never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(1809,71,1809,74): warning CS0168: The variable 'dnf' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(1813,54,1813,56): warning CS0168: The variable 'ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(5017,34,5017,36): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(5087,42,5087,44): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(5154,42,5154,44): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(5192,42,5192,44): warning CS0168: The variable 'Ex' is declared but never used
1>C:\ActacomProjects\DEV-Google\Control\ModifyService.svc.cs(5267,42,5267,44): warning CS0168: The variable 'Ex' is declared but never used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

4 个答案:

答案 0 :(得分:84)

输出中出现此错误:

  

缺少编译器所需的成员' Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

您需要添加对DLL Microsoft.CSharp.dll 的引用。

答案 1 :(得分:13)

与Saminathan S在接受的答案中的评论相似。如果您正在使用.NETStandard项目(在我的情况下是NETStandard 2.0),您需要从NuGet添加Microsoft.CSharp而不是作为参考来解决此构建错误。我在Mac上使用Visual Studio社区。

答案 2 :(得分:1)

您还可以添加此文件来编辑.csproj文件,其结果与@ the-senator所说的相同:

<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />

答案 3 :(得分:0)

快速解决方案。

右键单击Packages> Add NuGet Packages...> Microsoft.CSharp

这对我有用。 [Mac,Visual Studio 2017社区]