Results 1 to 1 of 1

Thread: Serialization fails (Resolved)

  1. #1

    Thread Starter
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Serialization fails (Resolved)

    Hey, I've just run into a weird problem.

    This class serializes fine:

    Code:
    [Serializable]
    public struct KarmaRule
    {
         public string Rule;
         public double Value;
    };
    Now, "Rule" is a Regular Expression. I figured the Regex class probably isn't serializable, but I gave it a try anyway:

    Code:
    [Serializable]
    public struct KarmaRule
    {
         public Regex Rule;
         public double Value;
    };
    No dice. It fails. So I thought, here's an easy work around:

    Code:
    [Serializable]
    public struct KarmaRule
    {
         public string Rule;
         public double Value;
         
         // after the struct is deserialized,
         // set xRule = new Regex(Rule, RegexOptions.Compiled)
         [NonSerialized]
         public Regex xRule;
    };

    But it doesn't work! It says "There was an error reflecting type KarmaRule." What gives? It's not supposed to serialize something marked NonSerialized, and it works fine without the Regular Expression as part of the struct.

    Edit: I'm using an Xml Serializer. I was looking for the [XmlIgnore] Attribute. Stupid me.
    Last edited by sunburnt; Feb 10th, 2004 at 12:40 AM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width