System.InvalidCastException on create Excel.Application obj after installing Office XP PIA


Im writing a VB.Net app that automates Excel 2000.  I found the Office xp interop and installed it on my machine (note: I do not have office xp) oxppia.exe.  So after installing this, now I find that my app throws a System.InvalidCastException error on this line of code:

xlApp = CType(CreateObject("Excel.Application"), Excel.Application)

Which had been working for days before I installed the interop.  In hindsite, I guess maybe it was dumb to install the interop when I dont
have Office xp, but I couldnt clearly discearn that it would not work with office 2000.

Ive got the idea, that my gac is messed up now, I tried to uninstall the interop assemblies that I had just added into the gac,
but only 2 of the 4 would uninstall.
Office and StdOle would not allow removal.  ( I was using gacutil /u, and tried gacutil /uf)

Any help would be most welcome.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

test if it's created

dim obj as object

obj = CreateObject("Excel.Application"),

if obj.gettype is typeof(excel.application) then
aetheonAuthor Commented:
oooh found a good clue, I clicked on Excel under References in the Solution Explorer and it shows:
Name  Interop.Excel
Desc   Microsoft Excel 9.0 Object Library

That aint right?  I think I need to figure out how to re-install that dll
ok then you can instaiate it corectly as
Dim obj as new Excel.Application
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

aetheonAuthor Commented:
umm, yeah I can instantiat it as an obj.  And Excel as an application itself works fine.
I wonder if its some registry setting that now points to the wrong dll.
I still think it could be a gac thing.
that might not work because Excel.Application will always refer to the latest version of Excel.
Therefore, when you install Office XP PIA, it might update Excel.Application to Excel.Application.10

Why don't you try it with

xlApp = CType(CreateObject("Excel.Application.9"), Excel.Application)

it might work....
You can also try to revert it back by saving the following text with .REG extension and just run it.

Windows Registry Editor Version 5.00


and then get your fingers cross and try to run your own application again.

aetheonAuthor Commented:
good thinking testn, I thought you might be on to something, but, turns out that ::
   xlApp = CType(CreateObject("Excel.Application.9"), Excel.Application)
      didnt help, same invalid cast

  I ran regedit and manually found the key HKEY_CLASSES_ROOT\Excel.Application\CurVer
      and saw that the value was = Excel.Application.9
aetheonAuthor Commented:
In Visual Studio - I opened the object browser, and pointed to the 'Application' object under Excel
then grabbed the GUID from the description,
looked up the GUID in the registry {000208D5-0000-0000-C000-000000000046}
and found the key TypeLib = {00020813-0000-0000-C000-000000000046}

Then, I found that value as a key under the key TypeLib and deleted the '1.4' key under that
which pointed to 10.0 Excel Interop

That fixed it!   -guess I get the points : )

Bob LearnedCommented:
One, thing, though is that you are mixing early-bound and late-bound:

xlApp = New Excel.Application is all you need.
Bob LearnedCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: Dranizz {http:#9923244} & testn {http:#9924016} & TheLearnedOne {http:#9928104}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer
aetheonAuthor Commented:
I thank everyone for their input, however none of the comments provided a solution.
All of the comments were helpful from the standpoint of inspiring me to look in places
I may not have thought of on my own, especially the one from testn regarding the values
in the registry.
aetheonAuthor Commented:
I wanted to give 50 points to testn, but apparently that isnt possible,
so I will not give any points, and I wont accept an answer, cuz the best
by far was the one I found on my own.  This can be closed out in my opinion.
PAQed, with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.