【问题标题】:FileNotFoundException for System.Runtime 4.2.1.0 building v2 Azure Functions ProjectSystem.Runtime 4.2.1.0 构建 v2 Azure Functions 项目的 FileNotFoundException
【发布时间】:2018-12-14 17:47:10
【问题描述】:

我在尝试构建 Azure Functions v2 项目时遇到错误。奇怪的是,它并不总是发生。我尝试了 Visual Studio 2017 (15.9.3) 和 Visual Studio 2019 (Preview 1.1) 的各种组合,以及在 Hosted 2017 代理上构建 Azure DevOps,以及在 1.0.22、1.0 之间更改 Functions 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.

【问题讨论】:

标签: .net-core azure-functions


【解决方案1】:

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

试着把这个 bindingRedirect 放在 C:\Users\&lt;user&gt;\AppData\Local\Microsoft\VisualStudio\15.0_29f8d23a\devenv.exe.config 里面 &lt;configuration&gt; -> &lt;runtime&gt; -> &lt;assemblyBinding&gt; 哪里是所有其他 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>

【讨论】:

  • 奇怪的是你的回答还没有点赞。在结合 .Net Framework 和 .Net Core 3.0 项目时也会遇到这个问题
【解决方案2】:

我有同样的问题,我的解决方案是

  • 通过包管理器控制台安装nuget包 像这样: PM> Install-Package System.Runtime -Version 4.3.0
  • 重启我的电脑。

注意:这适用于 .Net core 1.1 MVC 项目。

【讨论】:

    猜你喜欢
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 2019-03-05
    • 2019-04-23
    • 2020-09-13
    相关资源
    最近更新 更多