zoukankan      html  css  js  c++  java
  • [.Net] 编译调试时正常,发布后无法正常运行

    发现是发布后的程序找不到App.config文件

    添加GetConfiguration(), 指定文件路径,可以解决问题:

     1 private void SetConfig()
     2 {
     3    try
     4    {
     5         Configuration config = GetConfiguration();//ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     6 
     7         if (config.AppSettings.Settings["dbconnect_read"] != null && config.AppSettings.Settings["dbconnect_write"] != null)
     8         {
     9               _dbConnectStrRead = config.AppSettings.Settings["dbconnect_read"].Value;
    10               _dbConnectStrWrite = config.AppSettings.Settings["dbconnect_write"].Value;
    11               _dbContext = new DBContext(_dbConnectStrRead, _dbConnectStrWrite);
    12          }
    13     }
    14     catch (Exception ex)
    15     {
    16         _logger.Debug(ex.Message);
    17     }
    18 }
    19 
    20 private static Configuration GetConfiguration()
    21 {
    22    string configFileName = string.Empty;
    23 
    24    try
    25    {
    26        ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
    27        var path = "./App.config";
    28        configFileMap.ExeConfigFilename = path;
    29        Configuration configObj = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
    30 
    31        return configObj;
    32     }
    33     catch (Exception ex)
    34     {
    35         throw ex;
    36     }
    37 }
  • 相关阅读:
    centos7搭建kvm
    python脚本与shell脚本的结合应用
    shell脚本常用命令组合
    服务器硬盘损坏恢复过程
    linux grup引导进入单用户下
    mysql 数据库设计查询规范
    mysql 8.0 远程连接问题
    linux新加硬盘的操作
    linux 添加硬盘到/home 目录
    linux设置最大连接数
  • 原文地址:https://www.cnblogs.com/panpan-v1/p/8126177.html
Copyright © 2011-2022 走看看