cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

SOLVED
Highlighted
Visitor

Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

Using the .NET SDK 5.8.0.

 

I'm seeing a problem where if you remove a property from a VirtualThing's PropertyCollection then try to add the same property name back later it will throw an exception "an item with the same key has already been added".

 

This is very simply to replicate:

 

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

getProperties().Remove("test");

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

 

The exception will be thrown on the second call to defineProperty.  Apparently the call to .Remove is not fully removing the property somehow behind the scenes.  But if you examine the collection it definitely has removed it.  So maybe the property name is being stored somewhere else as well?

 

Am I doing something incorrectly with the removal of the property?  There is no other way to do it that I can see.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

Hi @CSharpie.

 

I checked on this and found that defineProperty() creates both a property and a property definition. It appears you are removing the property, but not the definition. Try this:

 

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

getProperties().Remove("test");

getThingShape().getPropertyDefinitions().Remove("test");

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

 

Regards.

 

--Sharon

View solution in original post

5 REPLIES 5
Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

Hi @CSharpie.

 

Please explain the use case here. We're not understanding why you would create the property, immediately remove it, and then recreate it.  Are you seeing any errors?  Is your intent to remove the property or the value of the property?

 

This article references entities but the content may be helpful in your case as well.

 

Regards.

 

--Sharon

Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

The intent is to remove the property completely.  Keep in mind my example is only to show how to produce the issue.   Of course no one is going to add, remove, and add all at the same time.

 

I realize the use case is a low probability one but the API does not seem to be working as it should.  If the property has been removed there is no reason adding it back later should throw an exception.

 

Also, if the SDK is leaving remnants of a removed property lying around internally who knows what other issues this may create after the application has been running for a long time... memory leaks, whatever.

Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

Hi @CSharpie.

 

I checked on this and found that defineProperty() creates both a property and a property definition. It appears you are removing the property, but not the definition. Try this:

 

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

getProperties().Remove("test");

getThingShape().getPropertyDefinitions().Remove("test");

defineProperty("test", "", BaseTypes.STRING, new AspectCollection());

 

Regards.

 

--Sharon

View solution in original post

Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

Hi @CSharpie.

 

If the previous response provided the explanation you needed, please mark it as the Accepted Solution for the benefit of others on the community.

 

Regards.

 

--Sharon

Highlighted

Re: Removing a property from a VirtualThing's PropertyCollection doesn't seem to work

I tried this and it does solve our problem.  Thanks much!

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________