title: WCF: Interfaces, Generics and ServiceKnownType
body: <p>I have the following:</p>
  
  <pre><code>[ServiceContract]
  [ServiceKnownType(typeof(ActionParameters))]
  [ServiceKnownType(typeof(SportProgram))]
  [ServiceKnownType(typeof(ActionResult&lt;SportProgram&gt;))]
  public interface ISportProgramBl  
  {
      [OperationContract]
      IActionResult&lt;ISportProgram&gt; Get(IActionParameters parameters);
  }
  </code></pre>
  
  <p>When I run the Get method I get the following error:</p>
  
  <blockquote>
    <p>There was an error while trying to serialize parameter <a href="http://tempuri.org/:GetResult" rel="noreferrer">http://tempuri.org/:GetResult</a>. The InnerException message was 'Type 'PPS.Core.DomainModel.Support.Action.ActionResult`1[ [PPS.Core.DomainModel.SportProgram.ISportProgram, PPS.Core.DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' with data contract name 'ActionResultOfanyType: <a href="http://schemas.datacontract.org/2004/07/PPS.Core.DomainModel.Support.Action" rel="noreferrer">http://schemas.datacontract.org/2004/07/PPS.Core.DomainModel.Support.Action</a>' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.</p>
  </blockquote>
  
  <p>From this error I can see that it can resolve ActionResult but it can't resolve ISportProgram even though I have <strong>ServiceKnownType(typeof(ActionResult &lt; SportProgram >))</strong> on my service interface...</p>
  
  <p>Note this is the Reference stub that is generated looks like this, so I can see that the known types are being brought across correctly:</p>
  
  <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
  [System.ServiceModel.ServiceContractAttribute(ConfigurationName="SportProgramStb.ISportProgramBl")]
  public interface ISportProgramBl {
  
      [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISportProgramBl/Get", ReplyAction="http://tempuri.org/ISportProgramBl/GetResponse")]
      [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PPS.Core.DomainModel.SportProgram.SportProgram))]
      [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PPS.Core.DomainModel.Support.Action.ActionParameters))]
      [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PPS.Core.DomainModel.Support.Action.ActionResult&lt;PPS.Core.DomainModel.SportProgram.SportProgram&gt;))]
      object Get(object parameters);
  }
  </code></pre>
  
  <p>Why is this going wrong???? Note its getting through the WCF service correctly... but it throws the exception when the result is returned. </p>
  
  <p>Lastly ActionResult looks like this:</p>
  
  <pre><code>public interface IActionResult&lt;T&gt; 
  {
      T Result { get; set; } 
  }
  </code></pre>
  
  <p>Cheers
  Anthony </p>