WCF – nullable values are not working in generics

Today I spent couple of hours figuring out why I suddenly got an error “Referenced type ‘x`1, … with data contract name ‘xIF_Ph6aZR’ in namespace ‘x cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.”

It was working and what I did just little bit of re-factoring. What I found is that there is a combination of conditions that does not work, while every one of them works separately:

  1. Generic class is used as DataContract.
  2. This class has nullable DataMember property
  3. You want to reference your class in your client instead of creating in through wsdl.

public class DummnyContract where T: IBusinessObject

public DateTime? LastModified{get;set;}


and then you use it like this:

public interface IService
DummyContract Get(int id);


This just does not work when you reference your assembly with declaration of this class. You can have it without class being generic. Or, you can have generic without nullable property. But not together.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>