Reputation: 7959
We have an Azure Function which runs on .NET Framework v4.8 (FUNCTIONS_EXTENSION_VERSION
= ~1
and FUNCTIONS_WORKER_RUNTIME
= dotnet
). We have a staging instance of this, which runs perfectly well.
And then we have a production instance, to which we publish exactly the same code, but when we call the Function it won't start up due to the following exception:
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
is referenced due to a referenced project specifying the following path:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\System.Runtime.Caching.dll
However, it appears in the .csproj file as:
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
When I build the project, none of those DLLs are in the \bin folder, and I assume that the target machine is expected to have them in a conventional location.
We are publishing using Zip deploy directly from Visual Studio.
Also, I have tried removing the reference to C:\Program Files (x86)\...
and instead referencing via NuGet - this makes no difference.
I then tried setting Copy Local
= Yes
for System.Runtime.Caching
, cleaning, deleting \bin and \obj, then rebuilding and publishing, and then when I trigger the 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)
So why does the staging instance work but exactly the same code on the production instance fails to find the DLL?
UPDATE:
Here is the project file:
<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>
UPDATE 2:
I eventually built an entirely new Function App, copy-pasted the config from the original Function App, published the same code from the same running instance of Visual Studio... and the Function ran without any problems. :|
Upvotes: 0
Views: 766
Reputation: 7367
I have deployed an Azure function app by adding the references which you have provided.
I am able to run the function without any issues.
As per our discussion and as suggested in the comments, create a new Function app and deploy the Function app with the same configurations.
One of the options to clear dll
version compatibility issues is to add the assemblyIdentity
and bindingRedirect
with the old and new version of the package in the App.config
(create/add a new App.config file) file as mentioned in the MSDoc.
App.config
file and add the below settings.My App.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.Caching" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="4.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
why does the staging instance work but exactly the same code on the production instance fails to find the DLL?
There might be a difference in the framework for both staging and Environment. The app will behave differently based on the environment framework/setup.
Upvotes: 0