Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: casper on November 04, 2005, 05:48:51 am
-
When I'm trying to read all the tagged values of a connector ( source->destination Aggregation) I get the following error while looping through the tagged values.
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'EA.TaggedValue'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EF08950B-949E-435F-84A3-A59E3106C3BF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at nHibernateTemplateHelper.Main.GetConnectorTaggedValues(Repository repository, Object param) in D:\nHibernateTemplateHelper\Main.cs:line 107
public object GetConnectorTaggedValues(Repository repository, object param)
{
try
{
string[] parameters = (string[])param;
Connector c = repository.GetConnectorByGuid(parameters[0]);
if (c.TaggedValues.Count > 0)
{
string result = "";
foreach (TaggedValue tv in c.TaggedValues)
{
result = tv.Name + "=\"" + tv.Value + "\" ";
}
return result;
}
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine("Somthing went wrong while retrieving the tagged files." + exc);
}
return string.Empty;
}
Maybe I'm casting it wrong? or should I try a different approach?
-
Hello Casper
I have only taken a quick look at your code, but the one thing that stands out (as I cant see what you are "using") is the way you have declared your tagged value in the foreach loop.
You have this:
foreach (TaggedValue tv in c.TaggedValues)
{
result = tv.Name + "=\"" + tv.Value + "\" ";
}
Try it with specifying it as an EA type:
foreach (EA.TaggedValue tv in c.TaggedValues)
{
result = tv.Name + "=\"" + tv.Value + "\" ";
}
This may be of no consequence if its included above, but if its not then it may be your answer.
Best Regards.
-
Hi Tom,
Thanks for the reply, I appreciate the input. Nevertheless, I did use the EA namespace and that’s why the code compiled (If I didn't included the namespace I couldn't compile the code).
Some research in the EA namespace showed that there are several TaggedValue types like TaggedValue, TaggedValueClass and ITaggedValue (not counting IDualTaggedValue). I have tried all of them but all created the cast error.
----------
Update
----------
A colleague of mine has discovered the right class to use. Instead of casting it to a TaggedValue it must be casted to ConnectorTag.