Solved

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

Posted on 2003-12-11
14
478 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
ID: 9923244
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
ID: 9923372
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
ID: 9923411
ok then you can instaiate it corectly as
Dim obj as new Excel.Application
0
 

Author Comment

by:aetheon
ID: 9923687
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
ID: 9924016
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
ID: 9924032
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:aetheon
ID: 9924243
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
ID: 9924504
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
ID: 9928104
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
ID: 10246893
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
ID: 10247331
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
ID: 10247367
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
ID: 10304725
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now