Possible Duplicate:
Why XML-Serializable class need a parameterless constructor
I’m getting the run-time error as stated below.
Message=OutlookAddIn1.DeviceRegistrationRequest cannot be serialized because it does not have a parameterless constructor.
I’m perfectly clear why (it’s said in the error message) and how to solve it (trivial addition of the empty constructor). What I’m not clear about is why it’s required. I’ve found
this discussion but it’s mainly about MVC, which has nothing to do with my program (which is a console client for CRM Dynamics).
No it is nothing about MVC(sorry, I’ve misread your post). It is only about plain C#’py object creation. You see, take this class for an example:How would the deserializer know what to pass when your object is to be deserialized and constructed? He couldn’t guess. Thus, the framework requires that serializable objects have to have parameterless constructors, so it is safe to “just create” and it is your responsibility to make whole state settable via properties.
note: by the way – note that the constructor does not have to be public. Most serializers do very well with private parameterless constructors or none at all, if they implemented to use uninitialized object construction, that is available from Reflection in at least the .Net full profile.