Hi all,
after many hours of trying and searching I don't see another way than to ask the specialists here. It is not my first EA-Addin I develop but I fail in creating a Tagged Value for a Package. This is my code:
string error;
bool updated;
EA.Package internalPackage = repo.GetPackageByGuid(packageGUID);
EA.TaggedValue taggedValueConfig = internalPackage.Element.TaggedValues.AddNew("tvname", "Memo");
taggedValueConfig.Notes = "some notes text";
taggedValueConfig.Value = "some value text";
updated = internalPackage.Element.Update();
if (!updated) error = internalPackage.Element.GetLastError();
internalPackage.Element.TaggedValues.Refresh();
updated = internalPackage.Update();
if (!updated) error = internalPackage.Element.GetLastError();
AddNew gives me a valid tagged value object. Nowhere an error is shown. 'updated' is always true. But at the end the tagged value is not added to the collection.
On one hand the API documentation writes, that the 'TaggedValue' collection of the 'Element' class is readonly, which would explain the failed adding. Also the documentation for the 'Element' attribute of the package class says:
Element
Notes: Read only
The associated element object; use to get/set common information such as Stereotype, Complexity, Alias, Author, Constraints, Tagged Values and Scenarios.
So it states it is readonly but then it says it is used to get/set - amonst others - tagged values.
On the other hand I find many examples in the web for adding tagged values to elements (even in Ea-Documents, e.g. see
https://sparxsystems.com/resources/user-guides/14.0/automation/automation.pdf, page 298), 'AddNew' returns a valid tagged value object and throws no exception and I can't imagine any reason why the 'TaggedValue' collection of the 'Element' class should be readonly.
I think there must be a way to add new tagged values to a package element. So please help me and tell me, what I'm doing wrong. I'm helpless and maximum confused. I know, it's a lot of text, but I wanted to give as much information as possible.
I use EA14 on a Windows 10 machine and I'm programming with Microsoft Visual Studio Professional 2019.
Thanks in advance,
Jörg