title: OData Client Request Pipeline not working in Odata V4
body: <p>I am following the sample blog below to remove and add properties in request ODataEntry class. </p>
  
  <p><a href="http://blogs.msdn.com/b/odatateam/archive/2013/07/26/using-the-new-client-hooks-in-wcf-data-services-client.aspx" rel="nofollow">http://blogs.msdn.com/b/odatateam/archive/2013/07/26/using-the-new-client-hooks-in-wcf-data-services-client.aspx</a></p>
  
  <p>But even if the code works fine and adds and removes the properties correctly when I put breakpoint, all the entity properties goes to server un changed.</p>
  
  <p>Only difference I see this I am using the OData V4 and new Ondata client to hook up. </p>
  
  <p>My code looks below.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Client.Default;
  
  namespace Client
  {
  
  using Client.MvcApplication1.Models;
  
  using Microsoft.OData.Core;
  
  internal class Program
  {
      private static void Main(string[] args)
      {
          Container container = new Container(new Uri("http://localhost:55000/api/"));
  
          container.Configurations.RequestPipeline.OnEntryEnding(
              w =&gt;
              {
                  w.Entry.RemoveProperties("Name");
              });
  
          Test test = new Test();
          test.Name = "Foo";
          CustomFields cs = new CustomFields { ServiceId = 3 };
          cs.Foo1 = 2;
          test.S_1 = cs;
          container.AddToTests(test);
          container.SaveChanges();
      }
  }
  
  public static class Extensions
  {
  
      public static void RemoveProperties(this ODataEntry entry, params string[] propertyNames)
      {
  
          var properties = entry.Properties as List&lt;ODataProperty&gt;;
          if (properties == null)
          {
              properties = new List&lt;ODataProperty&gt;(entry.Properties);
          }
  
          var propertiesToRemove = properties.Where(p =&gt; propertyNames.Any(rp =&gt; rp == p.Name));
          foreach (var propertyToRemove in propertiesToRemove.ToArray())
          {
              properties.Remove(propertyToRemove);
          }
  
          entry.Properties = properties;
  
      }
  
      public static void AddProperties(this ODataEntry entry, params ODataProperty[] newProperties)
      {
          var properties = entry.Properties as List&lt;ODataProperty&gt;;
          if (properties == null)
          {
              properties = new List&lt;ODataProperty&gt;(entry.Properties);
          }
  
          properties.AddRange(newProperties);
  
          entry.Properties = properties;
  
      }
  }
  }
  </code></pre>
  
  <p>If I change and start listening to RequestPipeline.OnEntryStarting I get the validation error that new property is not defined in owning entity. But as per code for Microsoft.OData.CLient this error should not occure as there is a check for IEdmStructuredType.IsOpen but still error occurs. So issue seems deep in how owningStructuredType is calculated. On my container I do see the correct edm model with entities marked as IsOpen = true.</p>
  
  <p>Odata lib code which should pass but is failing</p>
  
  <pre><code>internal static IEdmProperty ValidatePropertyDefined(string propertyName, IEdmStructuredType owningStructuredType)
          {
              Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)");
  
              if (owningStructuredType == null)
              {
                  return null;
              }
  
              IEdmProperty property = owningStructuredType.FindProperty(propertyName);
  
              // verify that the property is declared if the type is not an open type.
              if (!owningStructuredType.IsOpen &amp;&amp; property == null)
              {
                  throw new ODataException(Strings.ValidationUtils_PropertyDoesNotExistOnType(propertyName, owningStructuredType.ODataFullName()));
              }
  
              return property;
          }
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>container.Configurations.RequestPipeline.OnEntryStarting(
                  w =&gt;
                  {
                      w.Entry.RemoveProperties("Name");
                      w.Entry.AddProperties(new ODataProperty
                                                {
                                                    Name = "NewProperty",
                                                    Value = 1
                                                });
                  });
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>The property 'NewProperty' does not exist on type 'Client.MvcApplication1.Models.Test'. Make sure to only use property names that are defined by the type.
  
     at Microsoft.OData.Core.WriterValidationUtils.ValidatePropertyDefined(String propertyName, IEdmStructuredType owningStructuredType)
     at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertySerializer.WriteProperty(ODataProperty property, IEdmStructuredType owningType, Boolean isTopLevel, Boolean allowStreamProperty, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, ProjectedPropertiesAnnotation projectedProperties)
     at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertySerializer.WriteProperties(IEdmStructuredType owningType, IEnumerable`1 properties, Boolean isComplexValue, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, ProjectedPropertiesAnnotation projectedProperties)
     at Microsoft.OData.Core.JsonLight.ODataJsonLightWriter.StartEntry(ODataEntry entry)
     at Microsoft.OData.Core.ODataWriterCore.&lt;&gt;c__DisplayClass14.&lt;WriteStartEntryImplementation&gt;b__12()
     at Microsoft.OData.Core.ODataWriterCore.InterceptException(Action action)
     at Microsoft.OData.Core.ODataWriterCore.WriteStartEntryImplementation(ODataEntry entry)
     at Microsoft.OData.Core.ODataWriterCore.WriteStart(ODataEntry entry)
     at Microsoft.OData.Client.ODataWriterWrapper.WriteStart(ODataEntry entry, Object entity)
     at Microsoft.OData.Client.Serializer.WriteEntry(EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, ODataRequestMessageWrapper requestMessage)
     at Microsoft.OData.Client.BaseSaveResult.CreateRequestData(EntityDescriptor entityDescriptor, ODataRequestMessageWrapper requestMessage)
     at Microsoft.OData.Client.BaseSaveResult.CreateChangeData(Int32 index, ODataRequestMessageWrapper requestMessage)
     at Microsoft.OData.Client.SaveResult.CreateNonBatchChangeData(Int32 index, ODataRequestMessageWrapper requestMessage)
     at Microsoft.OData.Client.SaveResult.CreateNextChange()
  </code></pre>