Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeInitializationException when a class have a property that return an XElement value #62

Open
GoogleCodeExporter opened this issue Aug 27, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.
create a simple class that have the a property that return an XElement value 
like this

    public class MyClass
    {
        private string _id;
        public String Id { get { return _id; } set { _id = value; } }

        private string _text;
        public String Text { get { return _text; } set { _text = value; } }

        public MyClass()
        {
        }

        public XElement XElement
        {
            get
            {
                return new XElement("MyClass",
                            new XAttribute("id", Id),
                            new XElement("Text", Text)
                    );
            }
        }
    }

2.
test the serializer in this way

        static void Main(string[] args)
        {
            MyClass req = new MyClass() { Id = "11", Text = "22" };
            string s = req.ToJson();
        }

What is the expected output? What do you see instead?
The correct serialized values
{"Id":"11","Text":"22"}

but you get the exception

What version of the product are you using? On what operating system?
Last ServiceStack.Text Dll on a Windows 7 Pro SP1 with VS 2010 Ultimate and 
.NET 4.0

Please provide any additional information below.

Original issue reported on code.google.com by stiliu...@hotmail.com on 16 Sep 2011 at 8:09

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant