ConfigurationManager.AppSettings - 返回NULL [英] ConfigurationManager.AppSettings - Returns Null

查看:2057
本文介绍了ConfigurationManager.AppSettings - 返回NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去阅读我的app.config设置和IM确保它工作之前,但现在它返回一个NullReferenceException。



我的代码获取设置如下:

  codeValueUtilRx = ConfigurationManager.AppSettings [CODEVALUE_UTIL_RX]斯普利特(';')了ToList(); 



我的应用程序,congfig如下:

 <&的appSettings GT; 
<添加键=LOGFILELOCATIONVALUE =C:\\RuleEditor\\/>
<添加键=CODEVALUE_UTIL_RXVALUE =GCN; GRP; NDC; SPEC; TCC/>
< /的appSettings>



我有一种感觉,它的东西看似显而易见的,我只是不能弄明白。香港专业教育学院试图移动应用程序,配置到不同的项目解决方案,并重新IVE文件,但没有运气。任何想法?


解决方案

香港专业教育学院试图移动应用程序,配置到不同的项目,在解决方案和香港专业教育学院重新创建该文件,但没有运气




你的代码是正确的(我已经测试),你需要确保你的应用程序。配置文件是在您的主项目(EXE)。


Im trying to read settings from my app.config and im sure it was working before but now it returns a nullReferenceException.

My code getting the settings is as follows:

codeValueUtilRx = ConfigurationManager.AppSettings["CODEVALUE_UTIL_RX"].Split(';').ToList();

My app-congfig is as follows:

<appSettings>
    <add key ="LOGFILELOCATION" value ="C:\\RuleEditor\\"/>
    <add key ="CODEVALUE_UTIL_RX"  value="GCN;GRP;NDC;SPEC;TCC"/>
</appSettings>

I have a feeling its something seemingly obvious, I just cant figure it out. Ive tried moving the app-config to different projects in the solution and ive recreated the file, but with no luck. Any ideas?

解决方案

Ive tried moving the app-config to different projects in the solution and ive recreated the file, but with no luck

your code is correct (i have tested), you need to make sure that your app.config file is in your main project (exe).

这篇关于ConfigurationManager.AppSettings - 返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆