Serialization of StringDictionary

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

    #1

    Serialization of StringDictionary

    I'm getting an error when I attempt to serialize a type StringDictionar y,
    error suggests type not marked for Serialization, could someone tell me how
    to go about this?

    Thanks.


  • Rob Teixeira [MVP]

    #2
    Re: Serialization of StringDictionar y

    In short, you can't. The type isn't marked as Serializable and doesn't
    implement ISerializable.

    As an alternative, you can use a ListDictionary. ListDictionarie s are
    serializable. Only difference is they take any type of object, not just
    strings.

    The other alternative is to write a custom string dictionary that is
    serializable.

    -Rob [MVP]

    "J.R" <someone@somewh ere.com> wrote in message
    news:UwZTa.5346 09$Vi5.13646190 @news1.calgary. shaw.ca...[color=blue]
    > I'm getting an error when I attempt to serialize a type StringDictionar y,
    > error suggests type not marked for Serialization, could someone tell me[/color]
    how[color=blue]
    > to go about this?
    >
    > Thanks.
    >
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Serialization of StringDictionar y

      J.R.
      In addition to Rob's suggestions.

      You could manually iterate the StringDictionar y in the containing class
      adding the items to the SerializationIn fo class in the GetObjectData method.
      This would assume the containing class implements the ISerializable
      interface (in addition to having the SerializableAtt ribute. I would add a
      number of items count before saving the items. So on deserialization I would
      know how many items to restore. Just remember the names you use in
      SerializationIn fo need to be unique, I would probably prefix the items &
      count from the StringDictionar y with some unique value.

      Hope this helps
      Jay

      "J.R" <someone@somewh ere.com> wrote in message
      news:UwZTa.5346 09$Vi5.13646190 @news1.calgary. shaw.ca...[color=blue]
      > I'm getting an error when I attempt to serialize a type StringDictionar y,
      > error suggests type not marked for Serialization, could someone tell me[/color]
      how[color=blue]
      > to go about this?
      >
      > Thanks.
      >
      >[/color]


      Comment

      • J.R

        #4
        Re: Serialization of StringDictionar y

        Thank you kind Sirs, for your prompt and informative responses. Once again,
        I've implemented your suggestions and it is working perfectly.

        John.

        "Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
        news:ODUrDwjUDH A.3152@tk2msftn gp13.phx.gbl...[color=blue]
        > In short, you can't. The type isn't marked as Serializable and doesn't
        > implement ISerializable.
        >
        > As an alternative, you can use a ListDictionary. ListDictionarie s are
        > serializable. Only difference is they take any type of object, not just
        > strings.
        >
        > The other alternative is to write a custom string dictionary that is
        > serializable.
        >
        > -Rob [MVP]
        >
        > "J.R" <someone@somewh ere.com> wrote in message
        > news:UwZTa.5346 09$Vi5.13646190 @news1.calgary. shaw.ca...[color=green]
        > > I'm getting an error when I attempt to serialize a type[/color][/color]
        StringDictionar y,[color=blue][color=green]
        > > error suggests type not marked for Serialization, could someone tell me[/color]
        > how[color=green]
        > > to go about this?
        > >
        > > Thanks.
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...