A duplicate property value [PropertyName] was encountered error

Hello everyone!

Today I stumbled upon an odd error. Couldn't really figured out what's wrong. So I have a VAF running in my vault during Before Create New Object Finalize event handler.

The script meant to set properties before the object is created. The first run after deployment is smooth sailing. However, on the second object creation and so on, it threw an error "A duplicate property value [PropertyName] was encountered". I double checked the variable returns only one value not multiple. Below is the snippet on how I set the properties after getting the data from the searching. Is this a known issue or a bug? Or perhaps I should add something to the script?

var oResults = env.Vault.ObjectSearchOperations.SearchForObjectsByCondition(oSc, true);
int theobjID = 0;               

                if (oResults.Count > 0)
                    foreach (ObjectVersion routing in oResults)
                        if (routing.ObjVer.Type == 101) 
                            theobjID = routing.ObjVer.ID;

                        break; //to make it run only once 

                var Remarks = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Remarks");
                aPropVal.PropertyDef = Remarks;
                aPropVal.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, fData[4]);
                aPropVals.Add(-1, aPropVal);

                var TheGroup = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Groups");
                aPropVal.PropertyDef = TheGroup;
                aPropVal.TypedValue.SetValue(MFDataType.MFDatatypeLookup, theobjID);
                aPropVals.Add(-1, aPropVal);

                env.Vault.ObjectPropertyOperations.SetProperties(env.ObjVer, aPropVals);

Thank you in advance!

  • Might the properties collection already contain a value for one of these properties? How is it populated? 

  • What I don't understand is, why the first attempt of object creation has no issue and then the error starts appearing on the next attempt. The properties collection is totally empty from what I can tell. As you can see on the code snippet above that the data on the first PropertyValue is coming from an array and the second one is a lookup of an object id from the searching function.

  • Where do you create aPropVals? 

  • I created that at the very top outside of the function as a public variable. I added multiple PropertyValue like below but still getting the same error. 

    PropertyValue aPropVal1 = new PropertyValue();
    var Remarks = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Remarks");
    aPropVal1.PropertyDef = Remarks;
    aPropVal1.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, fData[4]);
    aPropVals.Add(-1, aPropVal1);
    PropertyValue aPropVal2 = new PropertyValue();
    var TheGroup = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Groups");
    aPropVa2.PropertyDef = TheGroup;
    aPropVa2.TypedValue.SetValue(MFDataType.MFDatatypeLookup, theobjID);
    aPropVals.Add(-1, aPropVal2);

  • I have solved the issue. The PropertyValues must be inside the function. Placing it as a public variable will trigger the error apparently.

  • You should be very careful with any public members. In general you should reduce the scope of everything to the minimum possible; in this case within the method.

    What's happening here is that the first object version populates an entry in the collection, then the second object version adds another for the same property definition. As a result there's then two entries in the collection.

    My rule of thumb: never use public members on your vault application class, and use other long-lived items (e.g. static) sparingly and only if you understand the consequence of doing so.

  • Well noted, Craig. Thank you for the reminder.