Hi, I wrote a simple program to test the "out-of-the-box"
functionalities of the CMAB (Configuration Management Application
Block).
After having added 2 values to an hashtable, and having written that
hashtable (using the XmlHashtableSectionHandler) to an XML file (using
the XmlFileStorage) I try to read back the hashtable with those
values. I am adding a "string" value (with a string key) and a
"double" value (also with a string key) to the hashtable.
The problem is that even though it all seems fine in the xmlStorage
file, when I read back the hashtable from the Configurationmanager,
and try to get both the string and double value back, it seems that
they are both restored as strings, I mean, the hashtable (restored
from the xmlStorage file) has the double value converted as a string,
although it was stored as a double. So, an InvalidCastException is
thrown when I try to get the double value.
Anyone knows what the problem might be?
Thanks in advance,
Ricardo Pereira
*******************************
Piece of code where I read the hashtable:
*******************************
Hashtable table;
table=(Hashtable)ConfigurationManager.Read();
string s = (string)table["ip"];
double x = (double)table["numberOfX"];
********
App.config:
********
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="applicationConfigurationManagement"
type="Microsoft.ApplicationBlocks.ConfigurationMan agement.ConfigurationManagerSectionHandler,Microso ft.ApplicationBlocks.ConfigurationManagement,Versi on=1.0.0.0,Culture=neutral,PublicKeyToken=null"
/>
<section name="TestXMLConfiguration"
type="Microsoft.ApplicationBlocks.ConfigurationMan agement.XmlHashtableSectionHandler,Microsoft.Appli cationBlocks.ConfigurationManagement,Version=1.0.0 .0,Culture=neutral,PublicKeyToken=null"
/>
</configSections>
<applicationConfigurationManagement
defaultSection="TestXMLConfiguration">
<configSection name="TestXMLConfiguration">
<configProvider assembly="Microsoft.ApplicationBlocks.Configuratio nManagement,Version=1.0.0.0,Culture=neutral,Public KeyToken=null"
type="Microsoft.ApplicationBlocks.ConfigurationMan agement.Storage.XmlFileStorage"
path="MyXML.xml"
signed="false" encrypted="false" />
</configSection>
</applicationConfigurationManagement>
</configuration>
********
MyXML.xml:
********
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<TestXMLConfiguration>
<XmlSerializableHashtable
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Entries>
<Entry>
<key xsi:type="xsd:string">ip</key>
<value xsi:type="xsd:string">192.1683.1.1</value>
</Entry>
<Entry>
<key xsi:type="xsd:string">numberOfX</key>
<value xsi:type="xsd:double">4</value>
</Entry>
<Entry>
<key xsi:type="xsd:string">numberOfY</key>
<value xsi:type="xsd:double">3.4</value>
</Entry>
</Entries>
</XmlSerializableHashtable>
</TestXMLConfiguration>
</configuration>