Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

项目启动抛异常:The type initializer for 'Nested' threw an exception #288

Open
luoxgwb opened this issue May 27, 2024 · 4 comments

Comments

@luoxgwb
Copy link

luoxgwb commented May 27, 2024

已经注册 services.AddMemoryCache();

启动还是报错:Senparc.CO2NET.Exceptions.CacheException: IMemoryCache 依赖注入未设置!如果您使用的是本地缓存,请确保在 Startup.cs 中执行了 services.AddMemoryCache() 方法!

System.TypeInitializationException: The type initializer for 'Nested' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Nested' threw an exception.
---> Senparc.CO2NET.Exceptions.CacheException: IMemoryCache 依赖注入未设置!如果您使用的是本地缓存,请确保在 Startup.cs 中执行了 services.AddMemoryCache() 方法!
at Senparc.CO2NET.Cache.LocalObjectCacheHelper.get_LocalObjectCache()
at Senparc.CO2NET.Cache.LocalObjectCacheStrategy..ctor()
at Senparc.CO2NET.Cache.LocalObjectCacheStrategy.Nested..cctor()

@luoxgwb
Copy link
Author

luoxgwb commented May 27, 2024

经过长时间排查,日志组件从NLog切换到Serilog,在CreateHostBuilder方法中只要添加了UseSerilog,你们这个[Senparc.CO2NET]就会抛异常,我服了呀

@luoxgwb
Copy link
Author

luoxgwb commented May 27, 2024

只要没有添加UseSerilog方法,就算没有注册IMemoryCache(),也不会抛异常,注册了UseSerilog,不管怎么都会抛异常,我一直使用Redis缓存

@JeffreySu
Copy link
Contributor

@luoxgwb 可以发一下所有启动过程的代码,帮您排查一下,框架本身并没有对 Log 库做其他特殊处理。

@JeffreySu JeffreySu reopened this Sep 11, 2024
@JeffreySu
Copy link
Contributor

@luoxgwb 可以发一下所有启动过程的代码,帮您排查一下,框架本身并没有对 Log 库做其他特殊处理。

@luoxgwb 请问问题仍然存在吗?需要你能提供重现的代码才比较好判断。目前框架本身没有做限制。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants