3 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
確保項(xiàng)目中的配置文件(如果是web則為web.config,如果是Windows則為app.config)以以下方式啟動(dòng):
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="YourProjectName.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
</configuration>
請(qǐng)注意,在configuration元素內(nèi)部,第一個(gè)孩子必須是configSections元素。
在element 的name屬性中section,確保將其替換YourProjectName為實(shí)際項(xiàng)目的名稱。
我碰巧在一個(gè)類庫(kù)項(xiàng)目中創(chuàng)建了一個(gè)Web服務(wù),然后將配置文件(以實(shí)現(xiàn)端點(diǎn)配置)復(fù)制(覆蓋)到我的Windows應(yīng)用程序中,開始出現(xiàn)同樣的問題。我無(wú)意中搬走了configSections。
它對(duì)我有用,希望對(duì)您有所幫助

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
從c:\ Users \ username \ AppData \ Local \ appname和c:\ Users \ username \ AppData \ Roaming \ appname刪除舊的配置文件,然后嘗試重新啟動(dòng)應(yīng)用程序。

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果您已將自己的自定義配置部分添加到中App.Config
,請(qǐng)確保已在<configSections>
元素中定義了該部分。我添加了我的配置XML,但忘記了在頂部聲明配置部分-這導(dǎo)致了異常“配置系統(tǒng)無(wú)法初始化”。
添加回答
舉報(bào)