WCF reusing types with inheritance - cannot generate client code

160 views Asked by At

I was just getting an error message in Visual Studio 2013 stating "Failed to generate code for the service reference" when trying to update my service reference after adding a base class to a couple of my existing data contracts. For my service, I generate a client data contracts assembly which I reference in the client application so that I can check the "Reuse types in referenced assemblies" option. This allows me to share the data contract classes across multiple services that share them.

I identified a couple data contracts that were needlessly duplicating properties so I created a base class for them to inherit from.

[KnownType(typeof(MyClass1))]
[DataContract]
public class BaseClass
{
    public Guid ID {get; set;}
    public string Name {set; set;}
}

[DataContract]
public class MyClass1 : BaseClass

As soon as I inherited from the base class, my client application got the error failing to generate the client code, leaving me with an empty Reference.cs file.

1

There are 1 answers

0
xr280xr On BEST ANSWER

I had initially defined my base class as abstract so I first removed that. No luck. I also tried adding various KnownType and ServiceKnownType attributes with no luck. I decided this wasn't making any sense so I tried restarting Visual Studio and then updating the service reference. Voila! It generated it fine after restarting. I hope this saves someone some time!