Alright.. so after a lot of try and error I found out the method AcquireTokenByAuthorizationCode is no longer supported in the new versions of Microsoft.IdentityModel.Clients.ActiveDirectory. I now tried version 2.22 which works. The example uses v2.19.
In newer versions it is needed to use AcquireTokenByAuthorizationCodeAsync.