I know this has been an issue before in this group but I have not yet
found a solution for the problem here, so I ask again.
I am experiencing serious trouble with the PIAs for Office XP. I used
Excel from .NET via Automation with my own set of Interop Assemblies
built with tlbimp.exe and everything just worked fine. Then I
installed the Office XP PIAs which appears to having it broke
completely. Trying to get a running instance of Excel 2000 and storing
it in a variable of type Excel.Application (from the Excel 2002 PIA)
led to an InvalidCastException. So I abandoned the idea of using PIAs
and deinstalled them from the GAC again and deleted all keys the
shipped .reg-files had created in the registry. But to no avail.
Whenever I try to assign an instance of Excel.Application (received
from Microsoft.VisualBasic,GetObject()) to a variable of type
Excel.Application from my self-made Interop Assemblies (the ones that
worked perfectly before), I get the same InvalidCastException. The
code was completely unchanged, not a single line or reference had been
changed, but it did not work any longer.
I also tried a variation:
Excel.Application app = new Excel.Application();
app.Visible = true;
This had not been a problem before also, but now the last line fails
with an InvalidCastException with the additional information that
"QueryInterface for interface Excel._Application failed". Also, this
snippet of code looks quite odd to me. Excel.Application appears to be
an interface in the intellisense of c# and VB, but you never can
instantiate an interface with 'new'. And right: watching the
expression app revealed that what was instantiated there was an object
of class ApplicationClass not of interface Application. How does the
compiler do that trick? It works the same way in c# and VB, so it does
not seem to be one of the tricks Microsoft applied to VB to make it
look more comfortable for old VB6-Developers.
However, the question that is surely of more importance to me is: How
can I get my dear old self-brewed Interops running again? And how can
I do that WITHOUT having to reinstall the Framework, Visual Studio, or
even the OS? I remember faintly that QueryInterface is a method of
IUnknown, the interface every COM-Object supports, so when that fails,
COM itself must have been manipulated somehow? As mentiononed above I
did also remove all keys that had been inserted into the registry by
the PIAs installation batchfile. But something obviously still sticks,
so what is it?
Thank you for any help!