Author Topic: ImportPackageXMI returns error 0x800c0006  (Read 12873 times)

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
ImportPackageXMI returns error 0x800c0006
« on: January 13, 2015, 06:19:25 am »
Hello

I am writing a small add-in to allow us to load multiple XMI files in an Enterprise Architect project. So far it works in certain cases and does everything it is supposed to do, but there appears to be certain states in which the command ImportPackageXMI does not work as intended. One of these reproductible states is upon creating a brand new EAP file and attempting to import right away on the new Model root node.

Here is the add-in code:

Code: [Select]
private void loadProjectFromManifest(EA.Repository Repository)
    {
      try
      {
      
        OpenFileDialog openDialog = new OpenFileDialog();
        openDialog.Filter = "EA Integration Tool files (*.eai)|*.eai";
        openDialog.FilterIndex = 1;
        openDialog.RestoreDirectory = true;

        string manifestFilename = "";
        if (openDialog.ShowDialog() == DialogResult.OK)
        {
          manifestFilename = openDialog.FileName;
        }
        else
        {
          return;
        }

        ImportProjectFromManifest(Repository, manifestFilename);
      }
      catch (System.Exception ex)
      {
        MessageBox.Show(ex.Message + "Failed to load manifest file.");
      }
    }

public static void ImportProjectFromManifest(EA.Repository Repository, string manifestFilename)
    {
      string error = "";
      try
      {
        string line;

        Repository.EnsureOutputVisible("Script");
        Repository.ClearOutput("Script");

        
        // Read the file and display it line by line.
        System.IO.StreamReader file = new System.IO.StreamReader(manifestFilename);
        
        EA.Project eaProject = Repository.GetProjectInterface();
        EA.Package basePackage = Repository.GetContextObject() as EA.Package;

        while ((line = file.ReadLine()) != null)
        {
          //load the xmi file in the project under the selected root node
          if (line != "")
          {
            error = "";
            Repository.WriteOutput("Script", "Importing " + line, 0);
            error = eaProject.ImportPackageXMI(basePackage.PackageGUID, line, 0, 0);            
            Repository.WriteOutput("Script", "Error returned: " + error, 0);
            basePackage.Update();              
          }
        }
  
        file.Close();
        
      }
      catch (System.Exception ex)
      {
        MessageBox.Show(ex.Message + "Error while loading manifest file " + error);
      }
      Repository.Models.Refresh();
      Repository.RefreshModelView(0);
      Repository.WriteOutput("Script", "Finished!", 0);
      Repository.BatchAppend = false;
    }

The output, for every XMI file in the manifest, is this:

Code: [Select]
Error returned: Error:
Code = 0x800c0006
Source = Line : 0; Char : 0
Error Description = The system cannot locate the object specified.

I have tried looking for more information regarding this issue but there doesn't seem to be any. The "object" which the system cannot found is not specified, and I am not sure what I mush Refresh/Update/other in order to get the ImportPackageXMI function to work in a reliable way.

The command works when I open an existing EAP file and import on an existing model, but not 100% of the time.

Any ideas on how to get this to work properly?
      

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #1 on: January 13, 2015, 06:32:16 am »
http://winwiki.org/error-0x800c0006/ suggests this to be a corrupted file. Have you checked the file path/access rights for the XMI?

q.

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #2 on: January 13, 2015, 06:54:07 am »
The file works fine when imported manually through the Import/Export menu, and it also works fine when importing it with the add-in from an existing EAP file.

The EAP file, manifest file and xml files are all in the same folder.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13256
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ImportPackageXMI returns error 0x800c0006
« Reply #3 on: January 13, 2015, 06:00:41 pm »
Quote
The file works fine when imported manually through the Import/Export menu, and it also works fine when importing it with the add-in from an existing EAP file.

The EAP file, manifest file and xml files are all in the same folder.
I'm not quite sure why it would return this error, but if it works on an existing .eap file, why don't you create the .eap file first, close it, re-open it and then try to import the xmi files?

Geert

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #4 on: January 14, 2015, 01:39:02 am »
Quote
Quote
The file works fine when imported manually through the Import/Export menu, and it also works fine when importing it with the add-in from an existing EAP file.

The EAP file, manifest file and xml files are all in the same folder.
I'm not quite sure why it would return this error, but if it works on an existing .eap file, why don't you create the .eap file first, close it, re-open it and then try to import the xmi files?

Geert

That is the workaround we have been forced to do so far, but even that doesn't work 100% of the time on all workstations. It still manages to work sometimes, which is an improvement, but I was trying to figure out why that problem occurs in the first place... Our next development steps will include automated document generation based on that XMI import tool, so ideally we would like it to work on the first attempt
« Last Edit: January 14, 2015, 01:40:03 am by PSOSSA »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13256
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ImportPackageXMI returns error 0x800c0006
« Reply #5 on: January 14, 2015, 06:14:16 pm »
So if I understand it correctly it never works when creating a brand new EA Model and it mostly works when using an existing model.

It could be that the problem occurs because EA hasn't finished loading.
I'm not sure what the best way would be to test if it has finished loading, but you could try to wait for 30 seconds or so and only then try to start importing the xmi files.

Geert

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #6 on: January 15, 2015, 03:13:55 am »
Quote
So if I understand it correctly it never works when creating a brand new EA Model and it mostly works when using an existing model.

It could be that the problem occurs because EA hasn't finished loading.
I'm not sure what the best way would be to test if it has finished loading, but you could try to wait for 30 seconds or so and only then try to start importing the xmi files.

Geert

I just did a test this morning
Created a new EAP file, waited 15 minutes, tried importing, failed
Loaded an existing EAP file, imported right away, succeeded
Tried a new one again, failed

I tried using all the Refresh and Update functions I could find at every instruction in the add-in, but it still fails as soon as I call ImportPackageXMI

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #7 on: January 15, 2015, 07:47:50 am »
I believe I have found the problem
It seems like Enterprise Architect keeps some sort of "working folder" internally

Calling "ImportPackageXMI" with a filename, but no path (ex "file.xml" rather than "C:\folder\file.xml"), is interpreted as a file in that specific working folder

Opening EA through a shortcut, rather than by opening an EAP file, sets that working folder and doesn't change it as long as the application is running. Therefore, creating a new EAP or opening an existing one would make the import fail with a relative file path

Opening an EAP file in a different folder than the folder the manifest is located would have the same result

The only successful way to get this to work with a relative path is to launch Enterprise Architect by opening a file in the same folder as the xmi and manifest files, and load everything from there

By appending the correct folder to the filename in the manifest, all those use cases now work and import everything correctly

Mekugi

  • EA Novice
  • *
  • Posts: 13
  • Karma: +1/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #8 on: January 16, 2015, 10:54:30 pm »
@PSOSSA: I have the impression that the "working folder" you mentioned is set to the folder of the last file EA reads or writes. So if files in different folders are used, the "working folder" would change during EA's lifetime. Did you observe the same behavior?

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #9 on: January 17, 2015, 08:36:41 am »
Quote
@PSOSSA: I have the impression that the "working folder" you mentioned is set to the folder of the last file EA reads or writes. So if files in different folders are used, the "working folder" would change during EA's lifetime. Did you observe the same behavior?

I think it doesn't change while the process runs. I was getting different behaviors between opening an EAP file from the windows explorer, which launches EA, and trying to launch EA and then use File -> Open to open the same file. In the first case the working folder was the one the file is located in, but not in the second case

Aswin Krishnan H

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #10 on: January 22, 2015, 02:24:33 am »
Quote
I think it doesn't change while the process runs. I was getting different behaviors between opening an EAP file from the windows explorer, which launches EA, and trying to launch EA and then use File -> Open to open the same file. In the first case the working folder was the one the file is located in, but not in the second case

the same here !  :o anything can be done to get a consistent working folder behavior ?

PSOSSA

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #11 on: January 22, 2015, 03:44:19 am »
Quote
Quote
I think it doesn't change while the process runs. I was getting different behaviors between opening an EAP file from the windows explorer, which launches EA, and trying to launch EA and then use File -> Open to open the same file. In the first case the working folder was the one the file is located in, but not in the second case

the same here !  :o anything can be done to get a consistent working folder behavior ?

The only sure way is to use the absolute file path instead of a relative path. In my case, I extract the folder from the manifest file path returned by the OpenDialog, and append the xml filename at the end of it

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: ImportPackageXMI returns error 0x800c0006
« Reply #12 on: January 22, 2015, 09:12:50 am »
EA doesn't keep a working folder path.

Every application in Windows is running in a "current directory". Any non-absolute path will be relative to this directory. I believe that it can be set programmatically, but EA never does. This means that the current directory will always be the one that is set by Windows when EA starts.

If you edit the properties for the EA shortcut you can set the "Start In" option to any directory you like.
« Last Edit: January 22, 2015, 09:13:07 am by simonm »