0

I'm using WCF Data Services 5.6 with custom entity classes, and successfully reading data into entities which inherit from Catel's ModelBase. However, when I try to perform an insert or update back, the reflection used by Data Service fails on one of ModelBase's readonly properties "ValidationContext" which implements an interface that has no setters. The ValidationContext has both an [XmlIgnore] and [Browsable(false)] attribute defined within Catel.

I've tried removing the property in both the Configurations.RequestPipeline.OnEntryStarting and OnEntryEnding hooks, and also via the (older school) method of editing the xml in the WritingEntry event. But the exception below arises before any of these events get triggered.

So it looks like the Data Services Client is reflecting on the type before attempting to serialize, and spitting the error there because it can't interpret an IValidationContext as a valid entity type in the model.

One workaround I've successfully tested is to effectively replace the public ModelBase property with a non-public version:

internal new IValidationContext ValidationContext 
{ 
   get { return base.ValidationContext; } 
}

but this obviously isn't acceptable because then I can't use the ValidationContext elsewhere.

I believe this would also be a problem with proxies generated via "Add Service Reference" if you were to add any properties like this in counterpart partial class code for any entities.

Any advice? Can we replace/override any of the relevant Serializer methods?


The type 'Catel.Data.IValidationContext' has no settable properties. Source: Microsoft.Data.Services.Client at System.Data.Services.Client.ClientEdmModel.GetOrCreateEdmType(Type type) at System.Data.Services.Client.Metadata.ClientTypeUtil.TypeIsEntity(Type t, ClientEdmModel model) at System.Data.Services.Client.ODataPropertyConverter.TryConvertPropertyValue(ClientPropertyAnnotation property, Object propertyValue, HashSet1 visitedComplexTypeObjects, ODataValue& odataValue) at System.Data.Services.Client.ODataPropertyConverter.PopulateProperties(Object resource, String serverTypeName, IEnumerable1 properties) at System.Data.Services.Client.Serializer.WriteEntry(EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateRequestData(EntityDescriptor entityDescriptor, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BatchSaveResult.GenerateBatchRequest()
at System.Data.Services.Client.BatchSaveResult.BatchRequest() at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) at System.Data.Services.Client.DataServiceContext.SaveChanges()

Dave A-W
  • 609
  • 7
  • 13
  • We indeed decorated the property with XmlIgnore so it would be ignored. Catel also implements the IXmlSerializer and it does exclude the ValidationContext property. What you might wawnt to try is to try this: https://catelproject.atlassian.net/wiki/display/CTL/XmlSchema+generation – Geert van Horrik Feb 14 '14 at 07:50
  • Thanks Geert, I just tried this but am getting the same error. Unfortunately it looks like the WCF Data Services code has not been written to use XmlSchemaProviders (where present). If you stick with the auto-generated proxy classes from "Add Service Reference", they don't output anything with regards to an XmlSchemaProvider or DataContract attributes, so I suspect the underlying code is just using reflection directly. – Dave A-W Feb 27 '14 at 03:09
  • I think this is fixed in the latest version of Catel. Can you please try the latest nightly build? If not, please create an issue at http://www.catelproject.com/support/issue-tracker/ – Geert van Horrik Feb 27 '14 at 09:39
  • Thanks. I'm no longer working on this particular project so can't verify, but for other StackOverflow users can you outline what the fix was? I imagine this could still be an issue for non Catel users with WCF Data Services 5.6. – Dave A-W Sep 12 '14 at 04:51

0 Answers0