I was using
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
in .net 6, then I upgraded to .net8 and started getting exceptions. I replaced the package above with
<PackageReference Include="AutoMapper" Version="14.0.0" />
and that fixed my issues.