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. java之servlet学习基础(二)

    上一次写到Servlet的实现方法,主要还是通过继承HttpServlet来实现Servlet.下面主要是回顾一下HttpServletRequest和HttpServletResponse对象中的一 ...

  2. core的微服务相关

    网关是ocelot consul 服务发现 配置中心apollo

  3. ES6 Template Strings(转)

    转自:https://developers.google.com/web/updates/2015/01/ES6-Template-Strings Strings in JavaScript have ...

  4. eval函数的特点和作用

    eval(): 作用:它的作用是把对应的字符串解析成js代码并运行(将json的字符串解析成为JSON对象): 特点:它是一个全局函数: 缺点:1>在该函数内部申明的变量都是全局变量,且申明的变 ...

  5. Asp.net Zero 应用实战-官方示例PhoneBook学习1_修改1版

    适用Zero版本:ASP.NET Core & Angular 2+ (aspnet-zero-core-3.1.0). 该版本官方有两个solution文件夹:Angular(前端) 和 a ...

  6. CSS绝对定位的原点:是在border上、padding上还是在content上?

    用了那么久的绝对定位,却一直没在意一个问题,就是绝对定位的原点,究竟是在盒模型的哪一处.今天想到这个问题,直接搜索没有找到标准文档,也没有搜索到相关的问题,于是决定自己动手实现一下看看,并把这个结果发 ...

  7. OvO

    OvO 知乎 网易云 图书馆 B站 小众软件 360极速浏览器下载 开源下载工具 下载地址1 下载地址2 下载地址3

  8. 20175316盛茂淞 2018-2019-2 《Java程序设计》第7周学习总结

    20175316盛茂淞 2018-2019-2 <Java程序设计>第7周学习总结 教材学习内容总结 第八章 常用实用类 一.String类 String类在java.lang包中,jav ...

  9. JB的IDE可视化MongoDB、MySQL数据库信息

    一.问题: 在使用JB的IDE的时候(pycharm.IDEA等)可视化mysql和mongodb的数据库信息,效果如下 MySQL: MongoDB:  可视化数据表关系: 二.方法: 1.MySQ ...

  10. java开发过程中,报错Dangling meta character '*' near index 0,解决办法

    1.split方法转化字符串为数组: String[] strPicArr = map.get("hw_pic").toString().split("*"); ...