Sim*_*ver 8 memorycache asp.net-core
So this all worked fine before updating to AspNetCore 3 today.
I am using a memory cache with dependency injection (IMemoryCache cache).
I add it to my middleware with services.AddMemoryCache();
and do NOT set a size, but I still end up with the error message:
Cache entry must specify a value for Size when SizeLimit is set.
When I inspect the instance of MemoryCache and it does indeed have a size of 10240 set (see image).
问题是我已经找了一个小时,我不知道这是在哪里设置的。我的代码中没有任何地方SizeLimit或10240任何地方 - 包括配置文件。
当我切换到使用app.UseEndpoints而不是app.UseMvc()- 但我做了很多我不确定的更改时,它似乎已经开始。
这可能在哪里设置使我难以理解。?
Yog*_*ter 11
我设法通过AddEntityFrameworkSqlServer()从我的ConfigureServices()方法中删除调用来阻止抛出此异常Startup.cs:
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddEntityFrameworkSqlServer() // <-- Removed this
.AddDbContext<MyContext>(options =>
options.UseSqlServer(...)
)
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
显然AddEntityFrameworkSqlServer() EF Core 3 中不再需要调用:
构建大多数应用程序时不再需要调用此方法,包括那些在 ASP.NET 或其他地方使用依赖注入的应用程序。
感谢@Simon_Weaver提供有关 EF Core 的线索!
| 归档时间: |
|
| 查看次数: |
3387 次 |
| 最近记录: |