Serializing NameValuePairs

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

    #1

    Serializing NameValuePairs

    I need to store some sort of Name-Value collection in the Application State.

    I keep trying different ones, but it errors out saying that they are not
    serializable. Do I need to write my own or is there one in the Framework
    that is serializable?

    I've tried NameValueCollec tion, Dictionairy<str ing,string>,
    StringDictionai ry, etc (you know...everythi ng that implements IDictionairy
    and can't be serialized)

    What type does everyone else use that can be serialized?


  • John Murray

    #2
    Re: Serializing NameValuePairs

    Objects that implement IDictionary are not serializable... .

    Typically what I do is mark the field as not serializable and then
    implement a property with a get/set that takes an array value, parses
    each item into it's name/value component and inserts them into the
    IDictionary based field.



    INeedADip wrote:[color=blue]
    > I need to store some sort of Name-Value collection in the Application State.
    >
    > I keep trying different ones, but it errors out saying that they are not
    > serializable. Do I need to write my own or is there one in the Framework
    > that is serializable?
    >
    > I've tried NameValueCollec tion, Dictionairy<str ing,string>,
    > StringDictionai ry, etc (you know...everythi ng that implements IDictionairy
    > and can't be serialized)
    >
    > What type does everyone else use that can be serialized?
    >
    >[/color]

    Comment

    • Steve Long

      #3
      Re: Serializing NameValuePairs

      I just wrote my own collection that's serializable. It works sweet.

      Steve

      "INeedADip" <INeedADip@gmai l.com> wrote in message
      news:eQUFRUfHGH A.1132@TK2MSFTN GP10.phx.gbl...[color=blue]
      > I need to store some sort of Name-Value collection in the Application[/color]
      State.[color=blue]
      >
      > I keep trying different ones, but it errors out saying that they are not
      > serializable. Do I need to write my own or is there one in the Framework
      > that is serializable?
      >
      > I've tried NameValueCollec tion, Dictionairy<str ing,string>,
      > StringDictionai ry, etc (you know...everythi ng that implements IDictionairy
      > and can't be serialized)
      >
      > What type does everyone else use that can be serialized?
      >
      >[/color]


      Comment

      • INeedADip

        #4
        Re: Serializing NameValuePairs

        Could you give me a small example so I know where to start?


        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Serializing NameValuePairs

          John,

          This isn't completely true. Objects that implement IDictionary are not
          XML serializable. Using regular serialization, they serialize just fine.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m


          "John Murray" <jmurray@pluck. com> wrote in message
          news:%23oNh1YfH GHA.2696@TK2MSF TNGP14.phx.gbl. ..[color=blue]
          > Objects that implement IDictionary are not serializable... .
          >
          > Typically what I do is mark the field as not serializable and then
          > implement a property with a get/set that takes an array value, parses each
          > item into it's name/value component and inserts them into the IDictionary
          > based field.
          >
          >
          >
          > INeedADip wrote:[color=green]
          >> I need to store some sort of Name-Value collection in the Application
          >> State.
          >>
          >> I keep trying different ones, but it errors out saying that they are not
          >> serializable. Do I need to write my own or is there one in the Framework
          >> that is serializable?
          >>
          >> I've tried NameValueCollec tion, Dictionairy<str ing,string>,
          >> StringDictionai ry, etc (you know...everythi ng that implements
          >> IDictionairy and can't be serialized)
          >>
          >> What type does everyone else use that can be serialized?[/color][/color]


          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Serializing NameValuePairs

            Actually, the three classes that you mentioned are ALL serializable.
            Are you sure it is these instances, or is it something else that you are
            trying to store in the application state?



            "INeedADip" <INeedADip@gmai l.com> wrote in message
            news:eQUFRUfHGH A.1132@TK2MSFTN GP10.phx.gbl...[color=blue]
            >I need to store some sort of Name-Value collection in the Application
            >State.
            >
            > I keep trying different ones, but it errors out saying that they are not
            > serializable. Do I need to write my own or is there one in the Framework
            > that is serializable?
            >
            > I've tried NameValueCollec tion, Dictionairy<str ing,string>,
            > StringDictionai ry, etc (you know...everythi ng that implements IDictionairy
            > and can't be serialized)
            >
            > What type does everyone else use that can be serialized?
            >[/color]


            Comment

            Working...