[The constructor of the deserialization "XXX" type object is not found.] Solution

Source: Internet
Author: User

[The constructor of the deserialization "XXX" type object is not found.] The error is generally because the class to be deserialized or its parent class (for example, inherits the dictionary class) implements the iserializable interface without serializing the constructor, at this time, you only need to add the serialization constructor to deserialize it. Note that a class or its parent class implements the iserializable interface, which indicates that custom serialization is enabled, and the serialization constructor and getobjectdata function must be compiled according to the custom serialization rules, see the following two examples.

[Serializable] class test: iserializable // The class implementing the iserializable interface {public test () {}// the class implementing the iserializable interface must contain a serialized constructor; otherwise, an error occurs. Protected test (serializationinfo, streamingcontext context) {value = info. getboolean ("test_value") ;}# region iserializable member public void getobjectdata (serializationinfo info, streamingcontext context) {base. getobjectdata (Info, context); info. addvalue ("test_value", value) ;}# endregion public bool value {Get; Set ;}}

[Serializable] class test: dictionary <string, string> // The parent class implements the iserializable interface (Dictionary implements the iserializable Interface) {public test () {} // if the parent class implements the iserializable interface, the subclass must also have a serialized constructor. Otherwise, an error occurs during deserialization. Protected test (serializationinfo, streamingcontext context): Base (Info, context) {value = info. getboolean ("test_value");} public override void getobjectdata (serializationinfo info, streamingcontext context) {base. getobjectdata (Info, context); info. addvalue ("test_value", value) ;}public bool value {Get; Set ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.