C # is inaccessible due to its level of protection and can only handle detailed code descriptions of public types

Source: Internet
Author: User
Encountered an error in implementing C # exporting the list data to an XML file [with Source]: not accessible because of its level of protection. Only public types can be processed.

The line of code that generated the error:

XmlSerializer XmlSerializer = new XmlSerializer (typeof (List<usermodel>));

Reason for error: class definition in the following code is:

Class Usermodel

No public access modifier added

    <summary>///User entity class//////////////////////////NOTE: The class must have the access modifier: public, otherwise an error occurs:    Only public types can be processed.        </summary> [Serializable] public class Usermodel {private Long id = 1;        private string name = "Name";        private int gender = 0;        private int age = 20;        private string userName = "UserName";        private string password = "password";            Public long ID {get {return Id;}        set {id = value;}            } public string Name {get {return Name;}        set {name = value;}            } public int Gender {get {return Gender;}        set {gender = value;}            } public int Age {get {return-age;}        set {age = value;}            } public string UserName {get {return UserName;}        set {userName = value;} } public string Password {get { return password;        } set {password = value;} }    }
Related Article

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.