halitpeker / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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: