python未将对象引用设置到对象的实例_20190705_关于winform程序修改程序名后, 报未将对象引用设置到对象的实例...

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";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值