0

I have an object called Organization that represents different rows in a database table called ORGANIZATION. Some organizations represent merchants and the merchant can have a "MerchantAux" record.

The Organization class looks like this:

    [DataContract]
    public class Organization : Core.Framework.BaseEntity
    {
        [Key]
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public virtual MerchantAux MerchantAuxRecord { get; set; }

        public Organization()
        {
        }
    }

The MerchantAux class looks like this:

    [DataContract]
    public class MerchantAux : BaseEntity
    {
        [Key]
        [DataMember]
        public int Code { get; set; }
        [DataMember]
        public int SettlementDelay { get; set; }
        [DataMember]
        public Nullable<System.Guid> WalletSiteId { get; set; }
        [DataMember]
        public bool? AddCardNotPresent { get; set; }
        [DataMember]
        public bool? BatchEmailNotification { get; set; }
        [DataMember]
        public string CsvEmailRecipients { get; set; }

        [IgnoreDataMember]
        public virtual ICollection<Organization> Organizations { get; set; }

        public MerchantAux()
        {
             Organizations = new List<Organization>();
        }
    }

These objects are defined in a Models assembly. The WCF Service Assembly has a ServiceContract and OperationContracts to Get and Save Organizations.

Getting an organization works without issue. Saving an organization is failing with a VERY strange result.

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter boardingservice:organization. The InnerException message was 'The use of type 'MerchantAux' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.'. Please see InnerException for more details.

And there is no inner exception.

Oh yeah... Soap UI has no problem calling the Save method, but a .Net client throws the above error. Has anyone else seen this behavior where the serializer thinks that an object is a collection?

For the curious, I did try changing it to CollectionDataContract instead, but of course it fails straight away with an exception saying that MerchantAux doesn't implement IEnumerable (duh). Anyway... any ideas would be great.

rene
  • 41,474
  • 78
  • 114
  • 152
  • If you try a concrete class instead of ICollection etc List does it change anything? – pagratios Mar 28 '18 at 22:49
  • Nope, I thought of that and the same behavior persists. Considering that Soap UI can serialize to the service without issue, I think there's something wrong with my test app. It's a simple console app in which I added a service reference to the WCF service... nothing I haven't done a thousand times before. I'm truly stumped here. – Jenna Ramsey Mar 29 '18 at 12:13
  • Does this answer https://stackoverflow.com/questions/9780766/wcf-serialization-exception-netdatacontractserializer helps? – pagratios Mar 29 '18 at 19:27

0 Answers0