0

I have an ASP.NET Core 6 app deployed in Azure AppService. After I updated Serilog.AspNetCore to 7th version it started crashing with:

Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0

(issue occurs only in AppService, locally everuthing works fine)

I suspect that deployment process cleans up dll's from .NET SDK similar to Azure Functions deployment flow. In Azure Functions this issue can be resolved with

<FunctionsPreservedDependencies Include="Microsoft.Extensions.Logging.Abstractions.dll" />

or

<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

Is there something similar for AppService?

Note: After downgrading the package to 6th version, everything works fine

Note 2: I don't have access to Advanced Tools, so cannot verify what files are being deployed (restricted by my company's DevOps)

Edit: Here's my csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <UserSecretsId>1bcc1cf7-6fce-4196-9bb5-a7aa29a04078</UserSecretsId>
    <RootNamespace>MyApp</RootNamespace>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.13" />
    <PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyApp.AppCore\MyApp.AppCore.csproj" />
  </ItemGroup>

</Project>
maxc137
  • 2,291
  • 3
  • 20
  • 32

2 Answers2

0

I have upgraded the Serilog.AspNetCore version to 7.0.0 and able to deploy and run the Azure App service without any errors.

enter image description here

  • After updating the package version run and build the application to get the changes reflected in the already created bin folder.

  • In your Local folder check whether you have the Microsoft.Extensions.Logging.Abstractions available under Serilog.AspNetCore => Microsoft.Extensions.Logging.

enter image description here

  • If you don't find it, install it manually from the NuGet Package and Re-deploy the App and check.

enter image description here

Or

  • Try to install the package from the Extensions tab (If you have access).

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
0

Turns out it wasn't App Service's fault, but .NET publishing (when publishing multiple project it messes up dependency versions sometimes):

Solution in my case was to add <IsPublishable>false</IsPublishable> to all test projects. Foolproof way of doing it is to add Directory.Build.targets file containing this to the repository's root:

<Project>

  <PropertyGroup Condition="'$(IsTestProject)' == 'true'">
    <IsPublishable>false</IsPublishable> <!-- Workaround for https://github.com/dotnet/sdk/issues/11953#issuecomment-770434716. Try removing after .NET 8 migration -->
  </PropertyGroup>

</Project>
maxc137
  • 2,291
  • 3
  • 20
  • 32