2013-07-27 79 views
2

我有一個問題讓我發瘋。我想添加哈希表設置(並添加了2個哈希表),但是當我嘗試使用它時,它拋出了一個異常(對象引用未設置爲對象實例)。然後我看着它的app.config是這樣的:將哈希表添加到設置

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
    <configSections> 
    </configSections> 

    </configuration> 

然後我加入的app.config文件中的兩個哈希表,現在我的配置文件看起來像這樣:

<?xml version="1.0" encoding="utf-8" ?> 

<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="APPNAME.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> 
    </sectionGroup> 
</configSections> 

<userSettings> 
    <APPNAME.Properties.Settings> 
     <setting name="UserInfo" serializeAs="System.Collections.Hashtable"> 
     <value /> 
     </setting> 
     <setting name="UserText" serializeAs="System.Collections.Hashtable"> 
     <value /> 
     </setting> 
    </APPNAME.Properties.Settings> 
</userSettings> 

而當我試圖使用哈希表時,它拋出以下異常: 無法分析屬性'serializeAs'的值。

我用Google搜索了但沒有成功,我在msdn上搜索也沒有找到。

回答

1

該Hashtable不支持序列化爲XML。 Settings.Settings中只有2個選項可用。 XML或字符串。改變你的序列化選項

serializeAs="Binary" 

同樣,在你的設置類,你必須指定序列化選項屬性作爲

[SettingsSerializeAs(SettingsSerializeAs.Binary)] 
+0

它是扔是我見過的第一次相同的異常。 –

+0

讓我看看你的更新設置文件和相關類 – Ehsan

+0

這是設置文件 - http://www.privatepaste.com/2e6e482fd5 –