Book a Demo

Author Topic: System.InvalidCastException???  (Read 4264 times)

eru

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
System.InvalidCastException???
« on: January 24, 2009, 03:45:01 pm »
My C# app is working fine on my dev machine, but when I deploy to the production machine, I get the following error when initializing EA:

Code: [Select]
System.InvalidCastException was unhandled
Message: Unable to cast COM object of type 'EA.RepositoryClass' to interface type
'EA.IDualRepository'. This operation failed because the QueryInterface call
 on the COM component for the interface with IID
'{4CD2CE1E-C301-4C16-9CA2-5A7EC4478C55}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The above error occurs when GetProjectInterface() is called:

Code: [Select]
myRepository = new RepositoryClass();
myProject = myRepository.GetProjectInterface();

Any ideas?

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: System.InvalidCastException???
« Reply #1 on: January 25, 2009, 04:45:06 am »
Do you have the same EA version on both machines?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: System.InvalidCastException???
« Reply #2 on: January 25, 2009, 04:53:14 am »
AFAIK you have to open an EA project (i.e. a repository or EAP file) before you can get a valid Project interface. Perhaps the problem happens because an internal COM call attempts to cast a null input.

Open something with your Repository and you should be able to retrieve the Project interface then.

Note that something similar can happen if you try to access the Project interface after you close an EA file or repository.
No, you can't have it!

eru

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: System.InvalidCastException???
« Reply #3 on: January 27, 2009, 06:15:28 am »
Thanks for everyone's response! It turns out my call to

Code: [Select]
using EA;
...
new RepositoryClass();
...

should have been fully qualified. Somehow, .NET on the production machine couldn't find the correct RepositoryClass() constructor and so the call 'new' returned an empty object. It was fine on my dev machine, but the behavior is not consistent between both machines.

Avoid this headache and always use fully-qualified names when calling into the Enterprise Architect API. Changing my code to:

Code: [Select]
new EA.RepositoryClass();

fixed the problem.
« Last Edit: January 27, 2009, 06:28:48 am by eru »