DataContract Inheritance Breaks Pipeline


This is very odd. I have a data contract Y, which inherits from X.
I have a Converter class that returns Y when you call it.
I have a WebGet that is returning an HttpResponseMessage<X>.
I do the following: return new HttpResponseMessage<X>(ConvertToY(SOMETHINGHERE));

When I do this, the operation gets called infinitely until A) the server crashes or B) the client gives up and just simply returns "12031/Unknown":

Example Code:
[XmlRoot(ElementName = "X")]
[DataContract(Name = "X", Namespace="urn:a.b.c")]
public class X{
   public string SomeValue { get; set; }

[XmlRoot(ElementName = "X")]
[DataContract(Name = "X"), Namespace="urn:a.b.c")]
public class Y : X{
 public string SomeOtherValue { get; set; }

   public int Id { get; set; }

[WebGet(UriTemplate = "{id}"]
public HttpResponseMessage<X> GetSomeValue(int id){
       return new HttpResponseMessage<X>(Converter.GetY(id));

public static class Converter{
 public static Y GetY(int id){
        return new Y{
                Id = id,
                SomeValue = "Some Value",
                SomeOtherValue = "Some Other Value"

When I replace my return with return new HttpResponseMessage<X>(new X(){ Id = id, SomeValue = "SomeValue" });, it works. When I use this converter class it fails. Can someone please tell me why this is the case? This is definately a bug and i could really use this fix asap.


digitalpacman wrote Feb 16, 2012 at 1:53 AM

So I'm guessing you didn't run this code, cause return new HttpResponseMessage<X>(new X(){ Id = id, SomeValue = "SomeValue" }); will fail. There is no Id property on X. Did you mean new Y?

DotNetRockStar wrote Feb 21, 2012 at 1:14 AM

I did mean new Y. Sorry about that.