Cannot find Property with name ‘x’ on the parent object–BCS Errors

We are going to investigate the following Issue in this blog post

Exception handed to HandleRuntimeException.HandleException Microsoft.BusinessData.MetadataModel.InvalidMetadataObjectException: Cannot find Property with name ‘HP’ on the parent object. The parent object may be returned by the LobSystem (External System) or it is created to be sent to LobSystem as input. This Property is referred to by child TypeDescriptor with Name ‘HP’ and Id ‘11284’ on Parameter with Name ‘supercarsList’ on Method with Name ‘GetAllSupercars’ on Entity (External Content Type) with Name ‘Supercar’ in Namespace ‘LightningTools.TheTestBcsModel.BdcModel1’.  

Click here, If you want to skip straight to the fix, otherwise, read on my friend, read on….

OK, lets have a look at this error. We can see that we have an issue with a missing Property. It mentions that this Property is referred to by a TypeDescriptor in our ‘GetAllSupercars’ Method.

If we have a look in the BDC Explorer we can see our TypeDescriptors under the GetAllSupercars method, so somewhere here is where our problem lies, the error says it’s the TypeDescriptor called ‘HP’ which is causing our problem.

BDC Explorer showing troublesome TypeDescriptor

OK, We know there is a property which is incorrect, lets start off by looking at what our’ ‘GetAllSupercars’ Method is returning

If we look at the picture above, look underneath the ‘GetAllSupercars’ method we can see that ‘supercarsList’ is a Parameter, in our case it’s a return parameter (Finder Methods return data) , next down the tree we have ‘SupercarsList’ this is telling SharePoint that we are bringing back a collection of items ( a collection of our Supercar class), it’s a TypeDescriptor set as IsCollection = True and it’s type is

System.Collections.Generic.IEnumerable`1[[LightningTools.TheTestBcsModel.BdcModel1.SupercarEntity, BdcModel1]]

Again we shall break this down.

System.Collections.Generic.IEnumerable`1[[#CLASSNAME#, #MODELNAMESPACE#]]

so we have an Enumerable collection of the ‘SupercarEntity’ class which exists in the ‘BcsModel1’ namespace

To view this information click on ‘SupercarsList’ in the BCS Explorer and view the details in the properties window

TypeDescriptor Properties Tool Pane

and under ‘SupercarsList’ we have ‘Supercar’ we are now describing what each individual Supercar in the ‘SupercarsList’ looks like. If we click on it in the BDC Explorer again we can see the properties are slightly different, we are no longer talking about a collection because we are talking about just one Supercar

TypeDescriptor Properties Tool Pane

OK. Just to recap

Explaining components of BDC Explorer

  1. We have a Return Parameter
  2. We have a collection of Supercars
  3. We have a Supercar

Now, under Supercar we are telling SharePoint what TypeDescriptors make up a Supercar.

TypeDescriptors of our Supercar External Content Type

Here we can see we have CarId, HP, Manufacturer, Model, Price, TopSpeed and ZerToSixtyTime.

We know from the ‘Supercar’ TypeDescriptor that we have told SharePoint that it’s Type is of one of our ‘SupercarEntity’ objects, it therefore makes sense that these TypeDescriptors match to each Property within the SupercarEntity class. When SharePoint calls our BCS Method it will hit our C# code, it will create a collection of our SupercarEntity objects and return them for rendering to the browser, SharePoint needs to know what these Properties are and how to handle them, this is why create TypeDescriptors for each property.

Lets have a look at our ‘SupercarEntity’ class

using System;
namespace LightningTools.TheTestBcsModel.BdcModel1
    public class SupercarEntity
        public int CarId { get; set; }
        public string Manufacturer { get; set; }
        public string Model { get; set; }
        public uint TopSpeed { get; set; }
        public TimeSpan ZeroToSixtyTime { get; set; }
        public uint HorsePower { get; set; }
        public decimal Price { get; set; }

if you’re quick on the ball you might notice something here…… got it yet?….. go on then I’ll tell you, HP doesn’t exist as a Property, in our code it is called ‘HorsePower’. Now the error message makes a bit more sense.

Cannot find Property with name ‘HP’ on the parent object.

We have defined a TypeDescriptor called HP which tells SharePoint to expect a Property called ‘HP’ but it doesn’t exist. We need to fix this.

How to fix

Option 1  – Change the TypeDescriptor Name

This is a fairly simple one, click on the ‘HP’ TypeDescriptor in the BDC Explorer and then view its properties

BDC Explorer - Updating Name property

If we change the ‘Name’ from HP –> HorsePower, matching the property in our C# class, it should work. Lets deploy!

External Content Type Data in Business Data Web Part


Bonus advice:

If you did still want the name to be displayed as HP instead of HorsePower you can set the properties as this

TypeDescriptor Properties Tool Pane Window

Notice that the TypeDescriptors name is still matching the name in the class but we have changed the Default Display Name to the value we want to use, check out how this looks now.

External Content Type Data in Business Data Web Part with updated column name

Option 2 – Change the Code Property

Open up the ‘SupercarEntity’ class and rename the HorsePower property to HP

Updated code for our External Content Type

By doing this it means we will also need to change any method which used the old method name

var supercarEntities = from car in externalSystemSupercars
           select new SupercarEntity()
               CarId = car.Id,
               HP = car.HorsePower,
               Manufacturer = car.Manufacturer,
               Model = car.Model,
               Price = car.BasePrice,
               TopSpeed = car.TopSpeed,
               ZeroToSixtyTime = car.ZeroToSixtyTime
Once all the methods are updated and the code builds OK, deploy!
External Content Type data in Business Data Web Part with updated TypeDescriptor Name
<Phill />
Tired of getting BCS errors? Why not try…BCS Meta Man

BCS Meta Man provides the ease of use of a drag and drop interface with the power of Visual Studio. It can save you days in time by generating the code required by SharePoint 2010 to read and write back to your External Systems.

Leave a comment