I was having the same issue, but found the fix to be adding the using Microsoft.AspNetCore.OpenApi version 8.0.13. I couldn't use the latest because of which version of NET I'm using - Since I'm running 8.0, the newest version wasn't compatible. Once I got the right version, then my error went away.
So quick summary, install the version that's compatible with the NET version you're using.