Configuration Block - Hashtable's values deserialization problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ricardo Pereira

    #1

    Configuration Block - Hashtable's values deserialization problem

    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 XmlHashtableSec tionHandler) 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 Configurationma nager,
    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 InvalidCastExce ption 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=(Hashtabl e)Configuration Manager.Read();

    string s = (string)table["ip"];
    double x = (double)table["numberOfX"];


    ********
    App.config:
    ********

    <?xml version="1.0" encoding="utf-8" ?>
    <configuratio n>
    <configSections >
    <section name="applicati onConfiguration Management"
    type="Microsoft .ApplicationBlo cks.Configurati onManagement.Co nfigurationMana gerSectionHandl er,Microsoft.Ap plicationBlocks .ConfigurationM anagement,Versi on=1.0.0.0,Cult ure=neutral,Pub licKeyToken=nul l"
    />
    <section name="TestXMLCo nfiguration"
    type="Microsoft .ApplicationBlo cks.Configurati onManagement.Xm lHashtableSecti onHandler,Micro soft.Applicatio nBlocks.Configu rationManagemen t,Version=1.0.0 .0,Culture=neut ral,PublicKeyTo ken=null"
    />
    </configSections>
    <applicationCon figurationManag ement
    defaultSection= "TestXMLConfigu ration">
    <configSectio n name="TestXMLCo nfiguration">
    <configProvid er assembly="Micro soft.Applicatio nBlocks.Configu rationManagemen t,Version=1.0.0 .0,Culture=neut ral,PublicKeyTo ken=null"
    type="Microsoft .ApplicationBlo cks.Configurati onManagement.St orage.XmlFileSt orage"
    path="MyXML.xml "
    signed="false" encrypted="fals e" />
    </configSection>
    </applicationConf igurationManage ment>
    </configuration>

    ********
    MyXML.xml:
    ********

    <?xml version="1.0" encoding="utf-8"?>
    <configuratio n>
    <TestXMLConfigu ration>
    <XmlSerializabl eHashtable
    xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
    <Entries>
    <Entry>
    <key xsi:type="xsd:s tring">ip</key>
    <value xsi:type="xsd:s tring">192.1683 .1.1</value>
    </Entry>
    <Entry>
    <key xsi:type="xsd:s tring">numberOf X</key>
    <value xsi:type="xsd:d ouble">4</value>
    </Entry>
    <Entry>
    <key xsi:type="xsd:s tring">numberOf Y</key>
    <value xsi:type="xsd:d ouble">3.4</value>
    </Entry>
    </Entries>
    </XmlSerializable Hashtable>
    </TestXMLConfigur ation>
    </configuration>
Working...