Windows 8.1中的配置文件

时间:2014-02-07 15:57:45

标签: .net winforms app-config windows-8.1

我正在尝试在Winforms的表单加载事件中执行以下代码

MessageBox.Show(IPAddress.Parse("127.0.0.1").ToString());

在除Windows 8.1和Windows Server 2012之外的所有操作系统中,它的工作和弹出127.0.0.1。

在Windows 8.1上,它给出了以下错误

        Error - The configuration section cannot contain a CDATA or text element. (C:\Program Files\eRS\Test.exe.Config line 3). Trace -    at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
    at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
    at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
    at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
    at System.Configuration.ConfigurationManager.GetSection(String sectionName)
    at System.Configuration.ConfigurationManager.get_AppSettings()
    at System.Diagnostics.PerformanceCounterLib.GetLocalizedPerfCounterMode()
    at System.Diagnostics.PerformanceCounterLib.IsLocalizedMode()
    at System.Diagnostics.PerformanceCounterLib.IsCustomCategory(String machine, String category)
    at System.Diagnostics.PerformanceCounter.Initialize()
    at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
    at System.Net.NetworkingPerfCounters.Initialize()
    at System.Net.Configuration.SettingsSectionInternal..ctor(SettingsSection section)
    at System.Net.Configuration.SettingsSectionInternal.get_Section()
    at System.Net.Sockets.Socket.InitializeSockets()
    at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
    at System.Net.IPAddress.Parse(String ipString)
    at Test.Form1.Form1_Load(Object sender, EventArgs e)

以下是我的app.config文件内容

<?xml version="1.0" encoding="utf-8"?>    <configuration>appSettings>wwgp89LZ6RQNuYqA4QW49%2b54BdPvtS7WTpSIbQD39tBU8g6XgzuTvCbTL%2feaONiaI6S9c0rNsbbJRqjiW4pfjcndQF8Ol%2fxBWbT1ae0HhxAfoq1ZeF9FTq9KD%2bu1fi1QgFqPhbnM3VJMBGMx4QIBRTHQcQpcEsi9xjkSQ1AT4dt5qWAbfonvvHc1HqCtkoAyB8I9PG7HK6l844sCWVqRrUh8%2biICB0K2i1lJkwmlwhPoEqvW%2bHaXuSit1rCYasIn%2balIQ8wVyW8H5y8aNNzWWfEsYJSID%2bI2b379DiyENBLnacTAQ%3d%3d</appSettings>
</configuration>

2 个答案:

答案 0 :(得分:0)

从我可以看到你粘贴的app.config文件设置不正确。

您需要使用appSettings而不是<appSettings>正确打开appSettings>部分

然后你需要把

wwgp89LZ6RQNuYqA4QW49%2b54BdPvtS7WTpSIbQD39tBU8g6XgzuTvCbTL%2feaONiaI6S9c0rNsbbJRqjiW4pfjcndQF8Ol%2fxBWbT1ae0HhxAfoq1ZeF9FTq9KD%2bu1fi1QgFqPhbnM3VJMBGMx4QIBRTHQcQpcEsi9xjkSQ1AT4dt5qWAbfonvvHc1HqCtkoAyB8I9PG7HK6l844sCWVqRrUh8%2biICB0K2i1lJkwmlwhPoEqvW%2bHaXuSit1rCYasIn%2balIQ8wVyW8H5y8aNNzWWfEsYJSID%2bI2b379DiyENBLnacTAQ%3d%3d

在键/值对内部,如下所示:

<appSettings>
    <add key="keynamehere" value="wwgp89LZ6RQNuYqA4QW49%2b54BdPvtS7WTpSIbQD39tBU8g6XgzuTvCbTL%2feaONiaI6S9c0rNsbbJRqjiW4pfjcndQF8Ol%2fxBWbT1ae0HhxAfoq1ZeF9FTq9KD%2bu1fi1QgFqPhbnM3VJMBGMx4QIBRTHQcQpcEsi9xjkSQ1AT4dt5qWAbfonvvHc1HqCtkoAyB8I9PG7HK6l844sCWVqRrUh8%2biICB0K2i1lJkwmlwhPoEqvW%2bHaXuSit1rCYasIn%2balIQ8wVyW8H5y8aNNzWWfEsYJSID%2bI2b379DiyENBLnacTAQ%3d%3d" />
</appSettings>

试一试,看看你得到了什么

答案 1 :(得分:0)