验证一个app.config文件 [英] Validate an app.config file
本文介绍了验证一个app.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们遇到无效的app.config文件问题.该程序在调试模式下运行良好,但是当尝试运行发行版时,该程序将崩溃.经过几个小时的调试/研究,我们意识到app.config文件存在问题.
无论如何,是否有在启动时检查app.config文件并向用户报告或写入调试文件,证明app.config文件的格式无效.
谢谢
We had an issue with an invalid app.config file. The program worked fine in debug mode, but when trying to run the released version, the program would just crash. After a couple of hours of debugging/researching, we realized there was a issue with the app.config file.
Is there anyway to check the app.config file at start up and report the user or write to a debug file that the app.config file is not in a valid format.
Thanks
推荐答案
这不是最好的解决方案,因为您要进行验证-没有.
您可以执行另一个app.config文件,该文件将在第一个失败时启动.
使用此类- 配置类.
It''s not the best solution beacuse you are asking for validation - there is no.
You can do another app.config file that will start when the first fails.
Use this class - Configuration class.
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"ConfigTest.exe.config"; // relative path names possible
// Open another config file
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
// read/write from it as usual
ConfigurationSection mySection = config.GetSection("mySection");
config.SectionGroups.Clear(); // make changes to it
config.Save(ConfigurationSaveMode.Full); // Save changes
希望对您有帮助.
Hope this will help you.
这篇关于验证一个app.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文