20190705_关于winform程序修改程序名后, 报未将对象引用设置到对象的实例
2024-10-09 19:30:41
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";
最新文章
- css中float left与float right的使用说明
- python模拟shell
- GPUImage实现过程
- Tennis Championship
- js 排序:sort()方法、冒泡排序、二分法排序。
- String类中常用的方法(重要)
- LAMP 版本查看
- C# string.format用法详解
- IntelliJ IDEA无法更新maven索引
- Echarts . 在柱状图中添加自定义值 (键值对)
- QT-1-环境搭建QT5.4.1&;MinGW4.9.1
- PID控制器(比例-积分-微分控制器)- III
- MyCAT简易入门 (Linux)
- C#打印格式
- [Go] Cookie 使用简介
- linux netcat命令使用技巧
- proxychains 安装
- hdu-1147(跨立实验)
- mysql 分页查询时,如何正确的获取总数
- Ngnix,EA(Enterprise Architect)
热门文章
- 【Kata Daily 190929】Password Hashes(密码哈希)
- 2、Django源码分析之启动wsgi发生了哪些事
- Pycharm激活码,最新2020Pycharm永久激活码!!!
- Docker系列04—跨主机网络方案(overlay/weave)
- js数组方法(管饱)
- maven install 时 pom中skip test
- Luogu P6833 【[Cnoi2020]雷雨】
- 在linux下,为什么 i386 ELF可执行文件默认从地址(.text)0x08048000开始分配。 而 x64是0x400000
- kafka消费者offset存储策略
- 解决自动安装Freebsd系统盘符无法确定问题