Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataContractSerializer and KnownTypes
Message
De
05/10/2012 10:20:06
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Titre:
DataContractSerializer and KnownTypes
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01554384
Message ID:
01554384
Vues:
49
I have a WebApi method that returns an Interface and, of course, when XML is requested the DataContractSerializer refuses to serialize the concrete type. I thought I could specify known types to get around this but I cannot get it to work.

Interface:
 public interface ISheetInfo
  {
    Guid _id { get; set; }
    string Name { get; set; }
    Guid OwnerId { get; set; }
  }
Class:
  [BsonIgnoreExtraElements]
  [DataContract]
  public class SheetInfo : ISheetInfo
  {
    [BsonId]
    [DataMember]
    public Guid _id { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public Guid OwnerId { get; set; }
  }
Web.config:
<system.runtime.serialization>
    <dataContractSerializer>
      <declaredTypes>
        <add type="LL.Web.Interfaces.ISheetInfo,LL.Web.Interfaces">
          <knownType type="LL.Repositories.Mongo.SheetInfo,LL.Repositories.Mongo" />
        </add>
      </declaredTypes>
    </dataContractSerializer>
  </system.runtime.serialization>
Anyone know what is, or might be, wrong? (References in web.config are correct)
Exception is:
Type 'LL.Repositories.Mongo.SheetInfo' with data contract name 'SheetInfo:http://schemas.datacontract.org/2004/07/LL.Repositories.Mongo' is not expected.
Répondre
Fil
Voir

Click here to load this message in the networking platform