You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Function因缺失.NET Framework DLL无法启动:程序集加载失败

Azure Functions v1(.NET Framework 4.8)生产环境System.Runtime.Caching加载异常问题

我们有一个基于.NET Framework v4.8运行的Azure Function,配置参数如下:

  • FUNCTIONS_EXTENSION_VERSION = ~1
  • FUNCTIONS_WORKER_RUNTIME = dotnet

预发布实例运行完全正常,但将完全相同的代码部署到生产实例后,调用Function时无法启动,抛出以下异常:

Could not load file or assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

引用配置说明

System.Runtime.Caching的本地引用路径为:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\System.Runtime.Caching.dll

项目.csproj文件中的引用配置片段:

<ItemGroup>
  <Reference Include="Microsoft.CSharp" />
  <Reference Include="System.Configuration" />
  <Reference Include="System.Runtime.Caching" />
</ItemGroup>

构建项目时,这些DLL不会输出到\bin目录,我们原本推测目标机器的常规系统路径下应该包含这些文件,发布方式为Visual Studio直接Zip deploy。

尝试的解决操作及结果

  • 移除本地路径引用,改用NuGet安装System.Runtime.Caching,问题无任何改善
  • 将System.Runtime.Caching的Copy Local属性设置为Yes,清理并删除\bin和\obj文件夹后重新构建发布,触发Function时抛出新异常:

Could not load file or assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)

核心疑问:为何预发布实例运行正常,生产实例部署相同代码却出现该DLL无法找到的问题?


更新1:完整项目文件内容

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <AzureFunctionsVersion>v1</AzureFunctionsVersion>
    <Configurations>Debug;Release;Staging</Configurations>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="Supertext.Smartling.AzFunction.csproj.DotSettings" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Autofac" Version="6.2.0" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.1.0" />
    <PackageReference Include="IdentityModel" Version="2.12.0" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
    <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Primitives" Version="5.0.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
    <PackageReference Include="Sendgrid" Version="6.3.4" />
    <PackageReference Include="Supertext.Base" Version="6.2.0" />
    <PackageReference Include="Supertext.Base.NetFramework.Configuration" Version="5.4.0-ci-20210506-142149" />
    <PackageReference Include="Supertext.Base.Security.Cryptography" Version="6.2.0" />
    <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
    <PackageReference Include="WindowsAzure.Storage" Version="7.2.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Supertext.AzFunc.Common\Supertext.AzFunc.Common.csproj" />
    <ProjectReference Include="..\Supertext.Smartling.Business\Supertext.Smartling.Business.csproj" />
    <ProjectReference Include="..\Supertext.Smartling.Client\Supertext.Smartling.Client.csproj" />
    <ProjectReference Include="..\Supertext.Smartling\Supertext.Smartling.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Runtime.Caching" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

更新2:最终解决结果

创建全新的Function App,复制原应用的所有配置,使用同一Visual Studio实例发布相同代码后,Function运行正常。


内容的提问来源于stack exchange,提问作者awj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 00:39:50