Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Kezia on August 25, 2009, 04:03:30 pm

Title: Failed creating new package
Post by: Kezia on August 25, 2009, 04:03:30 pm
Hi all,

I'm wondering why simple code below always gives me error
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

Code: [Select]
EA.Package newpkg = (EA.Package)pkg.Packages.AddNew("nuPkg", "");
newpkg.Update();

This is the way when creating new element or attribute, but it doesn't work on package. Anyone knows why?
Thanks :)
Title: Re: Failed creating new package
Post by: Geert Bellekens on August 25, 2009, 04:42:59 pm
try
Code: [Select]
EA.Package newpkg = (EA.Package)pkg.Packages.AddNew("nuPkg", "Package");
newpkg.Update();
Collection.AddNew() operation is a generic operation on the generic EA.Collection. It has to know which type of object you are creating.
Maybe that it doesn't throw an error in some cases because it can somehow figure out the type of object to create.

Geert
Title: Re: Failed creating new package
Post by: Kezia on August 25, 2009, 05:40:13 pm
Hi Geert,

It still throws the same error.. :(
But if I re-open the project, the package for both code above is created.

Cheers.
Title: Re: Failed creating new package
Post by: Geert Bellekens on August 25, 2009, 05:48:03 pm
Then I'm all out of suggestions except: ask Sparx Support.

Geert
Title: Re: Failed creating new package
Post by: «Midnight» on August 25, 2009, 11:05:49 pm
Check that you are using a very recent version and build of EA. I think there was a recent issue where child packages could not be created via the API. This was quickly rectified (i.e. in the next or next but one build) at the time. I think this was since EA 7.5 came out but I am not sure. The problem might have been present for a few builds before it was reported in the forum (i.e. since sometime in EA 7.1).