Add the MemoryCache in startup file to resolve the InvalidOperationException when creating the new ASP.NET core application. You can find the following code for your reference.
public void ConfigureServices(IServiceCollection services)
{
services.AddMemoryCache();
}