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 }
  • 相关阅读:
    第一次站立会议
    构建之法阅读笔记03
    软件工程概论学习进度条03
    四则运算三
    构建之法阅读笔记02
    软件工程概论学习进度条02
    四则运算二
    构建之法阅读笔记01
    软件工程概论学习进度条1
    软件工程个人作业01
  • 原文地址:https://www.cnblogs.com/panpan-v1/p/8126177.html
Copyright © 2011-2022 走看看