Newtonsoft.Json无法加载本地Azure Functions应用程序

时间:2018-06-05 08:38:04

标签: c# json.net azure-functions

我正在开发Azure功能" app"我在本地进行大部分测试,然后将DLL发布到Azure。我从三月份开始,直到几周前一直工作得非常好。

我主要使用macOS High Sierra(目前最新版本为10.13.4)和稳定频道上的Visual Studio进行开发和测试。

我最近更新了Visual Studio,当它提示我时,似乎已经更新为支持.NETStandard 2.0而非.NET Framework 4.7。*,但我的项目仍然在.NET Framework 4.7上。然而,当我试图通过对admin-endpoint的POST请求运行我的计时器触发器时,我发现错误告诉我应用程序无法加载Newtonsoft.Json。

我一直在努力解决这个问题,最后用.NETStandard 2.0创建了一个新项目,只是复制了文件,但同样的错误仍然存​​在。

Newtonsoft.Json是从Visual Studio for Mac中的内置NuGet包管理器安装的。

我还在Windows上测试了同一个项目(Windows Server 2012 R2标准版),但我得到了完全相同的错误。

错误我得到了:

[06/05/2018 08:17:18] System.Private.CoreLib: Exception while executing function: Posts. MyAzureFunctionsApp: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
[06/05/2018 08:17:18] 
[06/05/2018 08:17:18] Executed 'Posts' (Failed, Id=7c288cdf-7807-4450-92cd-c64370e241a5)
[06/05/2018 08:17:18] System.Private.CoreLib: Exception while executing function: Posts. MyAzureFunctionsApp: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.

Newtonsoft.Json版本11.0.0不存在,它目前版本为11.0.2,DLL版本为11.0.2.21924,所以我尝试了一个"绑定重定向。&# 34;这似乎也没有任何区别。

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json"
                publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
      <bindingRedirect oldVersion="11.0.0.0" newVersion="11.0.2.21924"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

的csproj-文件:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

我已经清理了十几次项目,创建了一个全新的项目,删除了~/.nuget,重新安装了Visual Studio并在Windows上测试了同一个项目。但我每次都会得到同样的错误。

1 个答案:

答案 0 :(得分:6)

尚不支持绑定重定向(GitHub issue)。

当针对netstandard2.0(NuGet package)时,Microsoft.NET.Sdk.Functions 1.0.13将Newtonsoft.Json 10.0.3作为依赖项。