Book a Demo

Author Topic: Problem: Packages  (Read 4500 times)

Lilleberg

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Problem: Packages
« on: October 28, 2008, 09:09:22 pm »
I want to add a new package named "EA Diagrams" into a package called "Playground View". But I get the following exception when I run my code:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


Here's my code. I get the exception at the line "newPackage.Update();":


EA.Package parentPackage = null;
EA.Package newPackage = null;

try
{
                
parentPackage = (EA.Package)m_Repository.Models.GetByName("Playground View");

newPackage = (EA.Package)parentPackage.Packages.AddNew("EA Diagrams", "Nothing");

parentPackage.Update();
newPackage.Update();
}
catch (Exception ex)
{

}

Do you have any idea of what I'm making wrong?

Thanks in Advance
/Johannes

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Problem: Packages
« Reply #1 on: October 28, 2008, 09:22:08 pm »
You failed to call Update() on the parent package before using it in code. Before you can add anything to a package - or other element - you need to call Update() to make EA save the element to the schema. Until you do that the element really does not exist, so EA will draw a blank (and return an exception) if you attempt to manipulate the element (such as adding something to a collection owned by the element).
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Problem: Packages
« Reply #2 on: October 28, 2008, 09:52:35 pm »
Johannes,

perhaps nothing is wrong with your code, but with EA. Build 832 threw an exception on Package.Update() and people had to downgrade to 831 because of that. They say it's fixed in 833 though.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Problem: Packages
« Reply #3 on: October 28, 2008, 10:01:18 pm »
Thanks Frank,

I had forgotten that. If the code above were amended to use Update, it would fail in build 832 for the reason you cite.

[edit]Please see Frank's post below.[/edit]
I have not had time to verify whether 833 resolved this problem, though it certainly is mentioned in the release notes. The problem was reported quite some time ago, as was the Sparx response that it had been addressed. Hopefully there's been enough time for thorough alpha testing at Sparx while 833 was still being set up.
« Last Edit: October 29, 2008, 10:54:00 am by Midnight »
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Problem: Packages
« Reply #4 on: October 28, 2008, 11:47:45 pm »
Quote
If the code above were amended

David,

I don't think the code needs to be amended at all. The parent package is being retrieved from the repository, so why would you want to update it before adding a new package?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Problem: Packages
« Reply #5 on: October 29, 2008, 10:55:06 am »
Oops. [He mumbles, while extracting his foot from his mouth.]

Quite correct Frank. Thanks for correcting me on that.

David
No, you can't have it!

Lilleberg

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Problem: Packages
« Reply #6 on: November 04, 2008, 08:48:19 pm »
Thanks for your help. I'll test "Package.Update" with build 833 when I have the possibility to do it. I'll report the result for you here in the near future.

Thanks!