Search code examples
c#.netamazon-web-servicesamazon-cloudwatchserilog

Nuget package Serilog.Sinks.AwsCloudwatch throwing TypeLoadExceptions because the parent type is sealed


I have recently updated a .NET 6 project to .NET 8 as well as updated all the packages to latest.

However when running the application when trying to load the logger I get hit with the below error

System.TypeLoadException: 'Could not load type 'Serilog.Sinks.AwsCloudWatch.CloudWatchLogSink' from assembly 'Serilog.Sinks.AwsCloudWatch, Version=4.0.182.0, Culture=neutral, PublicKeyToken=23b095b16108dcf5' because the parent type is sealed.'

Occurring here:

 var logger = new LoggerConfiguration()
     .WriteTo.AmazonCloudWatch(options, client);

The version of "Serilog.Sinks.AwsCloudWatch" is "4.0.182" (this did not change in the update)

The version of "Serilog" went from "3.0.1" to "3.1.1"

If you have any idea what is causing it do let me know! Many thanks in advance!


Solution

  • Was not able to reproduce the error with 3.1.1 version of the Serilog, check for explicitly installed Serilog.Sinks.PeriodicBatching nuget, since v4.0.0 PeriodicBatchingSink (base class for CloudWatchLogSink) is sealed.

    If the package installed explicitly - downgrade it (for example to 3.1.0), if not - explicitly install earlier version (possibly you will need to downgrade some other package which depends on this one).