I need to make a REST request and pass an object that has a property of type XElement.
An object:
public class Test
{
public string Property1 {get;set;}
public XElement PropertyXml {get;set;}
}
The code:
var testObj = new Test();
testObj.Property1 = "value";
testObj.PropertyXml = new XElement("test");
var level1 = new XElement("level1", "value111");
testObj.PropertyXml.Add(level1);
var client = new RestClient();
client.BaseUrl = new Uri(string.Format(_url));
var rRequest = new RestRequest(_address, Method.POST);
rRequest.RequestFormat = DataFormat.Json;
rRequest.AddBody(testObj);
var response = client.Execute(rRequest);
I get a "System.StackOverflowException" on a line with an AddBody call. PS I can pass the Test object using HttpClient (I use the PostAsJsonAsync method) instead of Restsharp.
Any ideas would be appreciated.
source
share