winform做了一个小项目, 其中要用到数据库连接, 字符串,

   private string ConnStringSource =   System.Configuration.ConfigurationManager.ConnectionStrings["ConnStringSource"].ConnectionString;

 就直接用的app.config配置文件

开发完成后, 也没有打包, 直接用debug下的文件发给用户了, 用户试用后, 觉得名字是英文的不方便, 想改下中文名

, 这个图是项目本来的名字;

,这个图是用户修改后的名字;

改完名字之后, 就一直包下图的经典错误:

解决办法是:

将配置文件也对应的改名, 比如你将 PrintBindRFID.exe 修改为 RFID打印.exe , 那么配置文件也得改成 RFID打印.exe.config;

问题到这里就解决了, 那么为什么是这样的呢?

看看System.Configuration.ConfigurationManager.ConnectionStrings 类的源码就知道了;

public static ConnectionStringSettingsCollection ConnectionStrings
{
get
{
object obj2 = GetSection("connectionStrings");
if ((obj2 == null) || (obj2.GetType() != typeof(ConnectionStringsSection)))
{
throw new ConfigurationErrorsException(SR.GetString("Config_connectionstrings_declaration_invalid"));
}
ConnectionStringsSection section = (ConnectionStringsSection) obj2;
return section.ConnectionStrings; //配置字符串从这个方法来
}
} //-----------------------------------------------------------------------------------------
public static object GetSection(string sectionName)
{
if (string.IsNullOrEmpty(sectionName))
{
return null;
}
PrepareConfigSystem();
return s_configSystem.GetSection(sectionName);//从这里来
} private static void EnsureConfigurationSystem()
{
object obj2 = s_initLock;
lock (obj2)
{
if (s_initState < 2)
{
s_initState = 1;
try
{
try
{
//s_configSystem使用这个进行实例化的, 转到它的构造函数
s_configSystem = new ClientConfigurationSystem();
s_initState = 2;
}
catch (Exception exception)
{
s_initError = new ConfigurationErrorsException(SR.GetString("Config_client_config_init_error"), exception);
throw s_initError;
}
}
catch
{
s_initState = 3;
throw;
}
}
}
}
//----------------------------------------------------------------------------------------- internal ClientConfigurationSystem()
{
this._configSystem = new ConfigSystem();
//ClientConfigurationHost看下这个类里面
this._configSystem.Init(typeof(ClientConfigurationHost), new object[2]);
this._configHost = (ClientConfigurationHost) this._configSystem.Host;
this._configRoot = this._configSystem.Root;
this._configRoot.ConfigRemoved += new InternalConfigEventHandler(this.OnConfigRemoved);
this._isAppConfigHttp = this._configHost.IsAppConfigHttp;
string schemeDelimiter = Uri.SchemeDelimiter;
}
//-----------------------------------------------------------------------------------------
internal sealed class ClientConfigurationHost : DelegatingConfigHost, IInternalConfigClientHost
{
// Fields
private ClientConfigPaths _configPaths;
private string _exePath;
private ExeConfigurationFileMap _fileMap;
private bool _initComplete;
private const string ConfigExtension = ".config";
internal const string ExeConfigName = "EXE"; //看到这里就不用再看下去了
internal const string ExeConfigPath = "MACHINE/EXE";

  

最新文章

  1. css中float left与float right的使用说明
  2. python模拟shell
  3. GPUImage实现过程
  4. Tennis Championship
  5. js 排序:sort()方法、冒泡排序、二分法排序。
  6. String类中常用的方法(重要)
  7. LAMP 版本查看
  8. C# string.format用法详解
  9. IntelliJ IDEA无法更新maven索引
  10. Echarts . 在柱状图中添加自定义值 (键值对)
  11. QT-1-环境搭建QT5.4.1&amp;MinGW4.9.1
  12. PID控制器(比例-积分-微分控制器)- III
  13. MyCAT简易入门 (Linux)
  14. C#打印格式
  15. [Go] Cookie 使用简介
  16. linux netcat命令使用技巧
  17. proxychains 安装
  18. hdu-1147(跨立实验)
  19. mysql 分页查询时,如何正确的获取总数
  20. Ngnix,EA(Enterprise Architect)

热门文章

  1. 【Kata Daily 190929】Password Hashes(密码哈希)
  2. 2、Django源码分析之启动wsgi发生了哪些事
  3. Pycharm激活码,最新2020Pycharm永久激活码!!!
  4. Docker系列04—跨主机网络方案(overlay/weave)
  5. js数组方法(管饱)
  6. maven install 时 pom中skip test
  7. Luogu P6833 【[Cnoi2020]雷雨】
  8. 在linux下,为什么 i386 ELF可执行文件默认从地址(.text)0x08048000开始分配。 而 x64是0x400000
  9. kafka消费者offset存储策略
  10. 解决自动安装Freebsd系统盘符无法确定问题