Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: stegeto22 on August 27, 2007, 06:37:25 am

Title: COMException adding a Class-Package-Dependency
Post by: stegeto22 on August 27, 2007, 06:37:25 am
Hi,

I want to add a dependency from a class to a package. When calling Update() of the Connector, I get an exception.

Code: [Select]
IDualPackage root = (IDualPackage)(model.Packages.AddNew("MyPkg", "Package"));
root.Update();

IDualPackage pkg = (IDualPackage)root.Packages.AddNew("MySubPkg", "Package");
pkg.Update();
IDualElement cls = (IDualElement)root.Elements.AddNew("MyClass", "Class");
cls.Update();
IDualConnector classDepPkg = (IDualConnector)cls.Connectors.AddNew("MyDependency", "Association");
classDepPkg.ClientID = cls.ElementID;
classDepPkg.SupplierID = pkg.Element.ElementID;
classDepPkg.Update(); // <-- COMException (HRESULT: 0x80010105 (RPC_E_SERVERFAULT))


Could someone help me, why I get this exception? I'm using version 7.0 (Build 815).

Bye
Tobias
Title: Re: COMException adding a Class-Package-Dependency
Post by: «Midnight» on August 27, 2007, 07:45:24 am
Sounds like a bug (a real one) Tobias.

Please submit this directly to Sparx. Use the Report a Bug link below Support at the bottom of any forum page.

Please let us know what Sparx has to say on the subject.

I suspect (without proof) that it may be too late to resolve your problem in build 816, but perhaps you can get this report to Sparx in time for build 817.

David
Title: Re: COMException adding a Class-Package-Dependency
Post by: stegeto22 on September 09, 2007, 11:06:14 pm
I've now got an answer to my bug report. It seems, it was a bug in my code.  :)

Quote
This exception is intentionally thrown due to attempting to create an Invalid Connector.
You cannot create an Association between a Package and a Class (if you try doing this in the user interface, it will also fail).

If you were meaning to create a Dependency, change the "Association"
string to "Dependency" and this should work.

Example:
Code: [Select]
IDualConnector classDepPkg = cls.Connectors.AddNew("MyDependency", "Dependency");
classDepPkg.ClientID = cls.ElementID;
classDepPkg.SupplierID = pkg.Element.ElementID;
classDepPkg.Update();

If you need to create connectors that go against strict UML syntax (such as a Class -> Package Association), you can disable the "Strict UML Syntax" option in "Tools | Options | Diagram" in EA.
Title: Re: COMException adding a Class-Package-Dependency
Post by: «Midnight» on September 10, 2007, 02:07:59 am
But, (how) can you disable strict UML checking from the API?
Title: Re: COMException adding a Class-Package-Dependency
Post by: stegeto22 on September 10, 2007, 06:15:35 am
I don't know.
But for my use case it's enough to replace "Association" with "Dependency".