Solved

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

Posted on 2003-12-11
14
475 Views
Last Modified: 2008-03-10
Hi,

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.
0
Comment
Question by:aetheon
  • 6
  • 2
  • 2
  • +2
14 Comments
 
LVL 8

Expert Comment

by:Dranizz
Comment Utility
test if it's created

dim obj as object

obj = CreateObject("Excel.Application"),

if obj.gettype is typeof(excel.application) then
0
 

Author Comment

by:aetheon
Comment Utility
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
0
 
LVL 8

Expert Comment

by:Dranizz
Comment Utility
ok then you can instaiate it corectly as
Dim obj as new Excel.Application
0
 

Author Comment

by:aetheon
Comment Utility
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.
0
 
LVL 18

Expert Comment

by:testn
Comment Utility
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....
0
 
LVL 18

Expert Comment

by:testn
Comment Utility
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

[HKEY_CLASSES_ROOT\Excel.Application\CurVer]
@="Excel.Application.9"
-------------------------------

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

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:aetheon
Comment Utility
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
0
 

Author Comment

by:aetheon
Comment Utility
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 : )


0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
One, thing, though is that you are mixing early-bound and late-bound:

xlApp = New Excel.Application is all you need.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Author Comment

by:aetheon
Comment Utility
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.
0
 

Author Comment

by:aetheon
Comment Utility
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.
Thanx.
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now