https://stackoverflow.com/questions/45875981/error-while-reading-json-file-in-dotnet-core-the-configured-user-limit-128-on

var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true);

You are creating file watchers, every time you access an setting. The 3rd parameter is reloadOnChange.

You have to make sure,

var configuration = builder.Build()

is only called once in your application and store it in a place where you can access it (preferably AVOID static fields for it).

Or just disable the file watcher.

  var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, false);

or cleaner:

var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", optional: true, reloadOnChange: false);

Best way is to abstract hat behind an interface and use dependency injection.

public interface IConfigurationManager
{
T GetAppConfig<T>(string key, T defaultValue = default(T));
} public class ConfigurationManager : IConfigurationManager
{
private readonly IConfigurationRoot config; public ConfigurationManager(IConfigurationRoot config)
=> this.config ?? throw new ArgumentNullException(nameof(config)); public T GetAppConfig<T>(string key, T defaultValue = default(T))
{
T setting = (T)Convert.ChangeType(configuration[key], typeof(T));
value = setting;
if (setting == null)
value = defaultValue;
}
}

Then instantiate and register it

services.AddSingleton<IConfigurationManager>(new ConfigurationManager(this.Configuration));

and inject it into your services via constructor

.net core 发布linux报错“The configured user limit (128) on the number of inotify instances has been reached”的更多相关文章

  1. 单元测试过多,导致The configured user limit (128) on the number of inotify instances has been reached.

    最近在一个asp.net core web项目中使用TDD的方式开发,结果单元测试超过128个之后,在CI中报错了:"The configured user limit (128) on t ...

  2. VSCode 出现错误 System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.

    方案一: sudo vim /etc/sysctl.conf 增加下面内容(环境变量) fs.inotify.max_user_watches = 1638400 fs.inotify.max_use ...

  3. 【docker】【redis】2.docker上设置redis集群---Redis Cluster部署【集群服务】【解决在docker中redis启动后,状态为Restarting,日志报错:Configured to not listen anywhere, exiting.问题】【Waiting for the cluster to join...问题】

    参考地址:https://www.cnblogs.com/zhoujinyi/p/6477133.html https://www.cnblogs.com/cxbhakim/p/9151720.htm ...

  4. eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“

    你的位置:首页 > Java编程 > eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“ eclipse发布项目报错:Multipl ...

  5. 64位linux报错Could not initialize class java.awt.image.BufferedImage

    最近碰到一个问题: 64位linux报错Could not initialize class java.awt.image.BufferedImage 在WIN平台下运行正常BufferedImage ...

  6. Linux报错之ping: www.baidu.com: Name or service not known

    Linux报错之ping: www.baidu.com: Name or service not known 出现这个以后,首先去ping下主机Ip,发现能ping通,但是出现另一个问题Destina ...

  7. Linux报错

    Linux报错 ------------------- 在VMware虚拟机中配置yum源时,执行 mount /dev/cdrom /mnt/cdrom 出现 mount: no medium fo ...

  8. iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...

  9. FXP登录Linux报错

    1.用FXP登录Linux报错: [info] subsystem request for sftp failed, subsystem not found.[右] [execute] /usr/li ...

随机推荐

  1. tiny4412--linux驱动学习(1)

    1,概述 linux设备驱动分为三种:字符驱动设备.块驱动设备.网络设备 架构: 1,字符设备驱动 是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符 ...

  2. Python中的计时器对象

    计时器对象用于特定时间运行的操作.往往被安排到特定的单独的线程上运行, 但是计时器初始化的时间间隔可能不是解释器实际执行操作时的实际时刻, 因为线程调度程序负责实际调度与计时器对象相对应的线程. Ti ...

  3. MVC Request生命周期(综合总结)

    当用户在浏览器输入一个URL地址后,浏览器会发送一个请求到服务器.这时候在服务器上第一个负责处理请求的是IIS.然后IIS再根据请求的URL扩展名将请求分发给不同的处理程序处理. 流程如下: 当请求一 ...

  4. pyadb关于python操作adb的资料

    3.最后adb命令由于是android的原生操作命令,支持实现的功能非常多.这里举几个pyapp里实现的功能例子:获取,修改手机当前使用的输入法(adb shell ime list),获取当前手机界 ...

  5. SQL SERVER 如何把1列多行数据 合并成一列显示

    示例 修改前:1列多行数据 修改后:合并成一列 示例语句 1 2 3 4 5 6 7 8 9 10 11 select 类别,     名称 = (         stuff(            ...

  6. layer.tips属性

    layer.tips(新加的内容,'选择节点',{time: 0, area: ['20%', '20%'], skin: 'layui-layer-rim', tips: [3, '#ffffff' ...

  7. AHOI——Day1个人感悟

    今天,是个bilibili的日子.(嗯?什么意思?) 洛谷已经尽力了: 于是我带着洛谷的祝福,来到了AHOI的考场--合肥一中. 其实我是考完才签到的,我一大早五点多就起来了,到考场后,在肯德基吃了早 ...

  8. SVG制作可爱小页面

    很久都没有在博客园上发表一些自己学的新东西了,只是在有空的时候逛一逛博客园而已,看来我不是一个真正的程序员,哈哈! 但是今天非常想和大家分享一个小东西,那是前两天在一个网页上看到了这个东西 我好奇中间 ...

  9. (转)MySql中监视增删改查和查看日志记录

    转载地址为:http://blog.51cto.com/hades02/1641652 首先在命令行输入 show global variables like '%general%' ,然后出现下面的 ...

  10. s6-5 TCP 连接的建立

    TCP 连接的建立 采用三次握手建立连接 一方(server)被动地等待一个进来的连接请求 另一方(the client)通过发送连接请求,设置一些参数 服务器方回发确认应答 应答到达请求方,请求方最 ...