Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-12-11
14
Medium Priority
?
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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
 

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

609 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