Rob Caron

Developer-related topics and other stuff.

Brady Gaster: new FxCop rule - serializable classes need default constructors

Brady Gaster: new FxCop rule - serializable classes need default constructors

  • Comments 3

In an earlier post, I talked about the different people creating FxCop rules. Brady Gaster, the impetus for that post has created another. Keep 'em coming, Brady!

fxcop rule : serializable classes need default constructors

with a little work and a lot of help from the guys over on the GDN FxCop messageboard, i'm able to publish this next rule. it does something like the one from yesterday, in terms of enforcing one of the most important serialization requirements imposed on us by the framework. here's the deal - like yesterday's rule, the serialization functionality within the framework needs to be able to create objects using a few assumptions. one of these assumptions is that serializable objects will be creatable without any construction parameters. so this rule basically enforces that requirement by ensuring that all objects marked with the Serializable attribute contain default public (instance-only!) constructors.

  • I'm a bit confused by this rule. As I understand it:

    A default public instance constructor is only required for classes using xml serialization (System.Xml.Serialization).
    The SerializableAttribute is only required for classes using the serialization framework (System.Runtime.Serialization).

    It seems to me this rule is incorrect. Anyone agree?
  • this rule is designed to enforce the first rule in your list. the second isn't considered.
  • The part that concerned me was this quote from blog: "so this rule basically enforces that requirement by ensuring that all objects marked with the Serializable attribute contain default public (instance-only!) constructors."
Page 1 of 1 (3 items)
Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post