cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
borovsky_d
Level 3

Automation interface and .NET

[CODE]
// Visual C# 2.0
01: using ISWiAuto14; // IS2008
.....
02: ISWiProject prj = new ISWiProject();
03: if (prj.OpenProject("MyProject.ism", false) != 0)
04: return 0;
05: ISWiProductConfig cfg = prj.ISWiProductConfigs[1];
06: ISWiRelease rls = cfg.ISWiReleases[1];
07: rls.Build();
...
[/CODE]

At line 6 I receive exception ("exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND)"), but this code worked correctly when I used IS12. :confused:
Labels (1)
0 Kudos
(4) Replies
MichaelU
Level 12 Flexeran
Level 12 Flexeran

It sounds like you don't have a release at index 1; perhaps you are using a new project or cleaned out your releases? I would expect, in C#, that the array index to start at 0 so you might try that instead if you have at least one release. Alternately, explore something like a foreach (ISWiRelease rls in cfg.ISWiReleases) { rls.Build(); } (or possibly a debugging message) to verify you are accessing releases in your project?
0 Kudos
borovsky_d
Level 3

1. No, I have a release at index 1.
2. cfg.ISWiReleases is not array; InstallShield automation interface indeces is 1-based (and I have 2 releases 🙂 );
3. "foreach" don't work too, for example:

foreach(ISWiProductConfig cfg in prj.ISWiProductConfigs)
{
foreach (ISWiRelease rls in cfg.ISWiReleases) //InvalidCastException, message: Unable to cast COM object of type 'System.__ComObject' to interface type 'ISWiAuto14.ISWiRelease'. This operation failed because the QueryInterface call on the COM component for the interface with IID
{
...
}
}

or

foreach(ISWiProductConfig cfg in prj.ISWiProductConfigs)
{
foreach (System.Object rls in cfg.ISWiReleases)
{
string typeName = rls.GetType().Name; // typeName == "__ComObject"
ISWiRelease rls2 = rls as ISWiRelease; // rls2 == null
}

Maybe it's Macrovisions error.:(
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

It looks like you were completely right about the 1-based indexing, but I cannot reproduce the problems you report with the foreach. Can you use the release name instead? If not, I'd suggest either trying to regenerate the COM interop that's been generated, or worst case move to another automation implementation or machine.
0 Kudos
borovsky_d
Level 3

Error isn't reproduce after reinstall IS2008 and uninstall IS12.
0 Kudos