Ive been asked to investigate why a customers system doesnt work (.net 2005), and eventually I have found the issue.
The system is a subset of a big enterprise solution, concerned with messaging.
The objects are passed about via MSMQ, using Binary Serialisation, and the objects were created from XML Schema (by xsd).
The schema were recently extended, and new properties to the objects added. These properties are all optional, which means that the optional parameters all have an additional ParameterSpecified Boolean, with the XmlIgnore Attribute.
Now when these objects are populated from the database via a routine that uses reflection, then the new properties are being set, But the PropertySpecified Flag is not (as a corresponding column doesnt exist in the DataRow).
Looking through the PropertyInfo object for the optional property shows that there are no attributes on the objct at this point.
As I see it I have 4 options, none of which fill me with joy.
1) Modify the reflection code, so that each time I find a property I then look to see if it also has a Specified property and set that to.
2) Create an Attribute and apply it to the optional parameters. - Not a good choice as it will need to be put back into the class definition by hand if the objects are regenerated at a later date.
3) Modify the classes again, and if the property is accessed, then set the Specified parameter - Has the same issues as 2, but has less impact on the reflection code as I dont need to examine attributes.
4) Modify the schemas and make these objects mandatory - I suspect that there is no way I'll get this past the business, and it causes all other kinds of problems.
So I guess Im asking, can anyone see an option 5?
The system is a subset of a big enterprise solution, concerned with messaging.
The objects are passed about via MSMQ, using Binary Serialisation, and the objects were created from XML Schema (by xsd).
The schema were recently extended, and new properties to the objects added. These properties are all optional, which means that the optional parameters all have an additional ParameterSpecified Boolean, with the XmlIgnore Attribute.
Now when these objects are populated from the database via a routine that uses reflection, then the new properties are being set, But the PropertySpecified Flag is not (as a corresponding column doesnt exist in the DataRow).
Looking through the PropertyInfo object for the optional property shows that there are no attributes on the objct at this point.
As I see it I have 4 options, none of which fill me with joy.
1) Modify the reflection code, so that each time I find a property I then look to see if it also has a Specified property and set that to.
2) Create an Attribute and apply it to the optional parameters. - Not a good choice as it will need to be put back into the class definition by hand if the objects are regenerated at a later date.
3) Modify the classes again, and if the property is accessed, then set the Specified parameter - Has the same issues as 2, but has less impact on the reflection code as I dont need to examine attributes.
4) Modify the schemas and make these objects mandatory - I suspect that there is no way I'll get this past the business, and it causes all other kinds of problems.
So I guess Im asking, can anyone see an option 5?