System.Runtime 4.2.1.0构建v2 Azure Functions项目的FileNotFoundException

时间:2018-12-14 17:47:10

标签: .net-core azure-functions

尝试构建Azure Functions v2项目时出现错误。奇怪的是,它并不总是发生。我尝试了Visual Studio 2017(15.9.3)和Visual Studio 2019(Preview 1.1)的各种组合,以及在Hosted 2017代理上的Azure DevOps中进行构建,以及在1.0.22、1.0之间更改了功能SDK。 23和1.0.24。

  • 在带有v1.0.24的Azure DevOps上,此错误始终会失败。
  • 它始终在VS 2019 v1.0.24上成功
  • 在VS 2017和2019上始终失败于v1.0.22
  • 无论其他组合是否失败,它们都是命中注定的。

这个问题似乎有点类似,但没有得到答案: .NET Core and Azure Functions - build error System.Runtime 4.2.0.0

这是错误:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
   at MakeFunctionJson.FunctionJsonConverter.TryRun()

Error generating functions metadata
    FunctionsCore   C:\Users\myusername\.nuget\packages\microsoft.net.sdk.functions\1.0.24\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets   39

这是我的.csproj文件:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <AssemblyName>MyProject.FunctionsCore</AssemblyName>
    <RootNamespace>MyProject.FunctionsCore</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.2" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

这是一些融合信息:

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/myusername/.nuget/packages/microsoft.net.sdk.functions/1.0.24/tools/net46/
LOG: Initial PrivatePath = NULL
Calling assembly : Cacs.MyProject.FunctionsCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/myusername/.nuget/packages/microsoft.net.sdk.functions/1.0.24/tools/net46/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myusername/.nuget/packages/microsoft.net.sdk.functions/1.0.24/tools/net46/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myusername/.nuget/packages/microsoft.net.sdk.functions/1.0.24/tools/net46/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/myusername/.nuget/packages/microsoft.net.sdk.functions/1.0.24/tools/net46/System.Runtime/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/myusername/source/repos/MyProject/MyProject/FunctionsCore/bin/Debug/netcoreapp2.1/bin/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myusername/source/repos/MyProject/MyProject/FunctionsCore/bin/Debug/netcoreapp2.1/bin/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myusername/source/repos/MyProject/MyProject/FunctionsCore/bin/Debug/netcoreapp2.1/bin/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/myusername/source/repos/MyProject/MyProject/FunctionsCore/bin/Debug/netcoreapp2.1/bin/System.Runtime/System.Runtime.EXE.

1 个答案:

答案 0 :(得分:0)

我解决了相同的错误,但是在another context中(在Visual Studio中生成T4模板时发生了)。

尝试将此bindingRedirect放在C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\15.0_29f8d23a\devenv.exe.config-> <configuration>-> <runtime>中的<assemblyBinding>里面,所有其他的bindingRedirect都在哪里

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>