473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'System.Invalid CastException'

Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation)
in my windows form...
I got the Exception

'System.Invalid CastException' : QueryInterface for interface
Excel._Applicat ion failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien
Nov 15 '05 #1
7 4713
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so, then
you will have to resort to either late binding, or performing a conditional
switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Julien" <ju************ @heuft.com> wrote in message
news:eL******** ******@TK2MSFTN GP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation)
in my windows form...
I got the Exception

'System.Invalid CastException' : QueryInterface for interface
Excel._Applicat ion failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien

Nov 15 '05 #2
I am trying to develop with excel 2000, maybe it will be better that I try
Excel XP !!!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> a écrit
dans le message de news: #t************* *@TK2MSFTNGP10. phx.gbl...
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so, then you will have to resort to either late binding, or performing a conditional switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Julien" <ju************ @heuft.com> wrote in message
news:eL******** ******@TK2MSFTN GP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation) in my windows form...
I got the Exception

'System.Invalid CastException' : QueryInterface for interface
Excel._Applicat ion failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien


Nov 15 '05 #3
It might help if you would post some code of the problem.
My guess is that what you are trying to send to excel isn't something
excel can handle.
Not sure what changing cultureinfo would fix. Then again, some code would
be helpful.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Julien,

Where did you get the primary interop assemblies that you are using in
..NET to access Excel from?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Julien" <ju************ @heuft.com> wrote in message
news:ua******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to develop with excel 2000, maybe it will be better that I try
Excel XP !!!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> a écrit
dans le message de news: #t************* *@TK2MSFTNGP10. phx.gbl...
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so,

then
you will have to resort to either late binding, or performing a

conditional
switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Julien" <ju************ @heuft.com> wrote in message
news:eL******** ******@TK2MSFTN GP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation) in my windows form...
I got the Exception

'System.Invalid CastException' : QueryInterface for interface
Excel._Applicat ion failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien



Nov 15 '05 #5
Thanks for replying, here is the code :

=============== =============== =============== ==========
private Excel.Applicati on ExcelObj = null;

public Form1()
{
// Initialize the Windows Components
InitializeCompo nent();
ExcelObj = new Excel.Applicati on();
// See if the Excel Application Object was successfully constructed
if (ExcelObj == null)
{
MessageBox.Show ("ERROR: EXCEL couldn't be started!");
System.Windows. Forms.Applicati on.Exit();
}
}

private void menuItem2_Click (object sender, System.EventArg s e)
{
// *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbo oks.Open("c:\co unter.xls",Type .Missing, Type.Missing,
Type.Missing,Ty pe.Missing,Type .Missing, Type.Missing,
Excel.XlPlatfor m.xlWindows, Type.Missing,Ty pe.Missing,
Type.Missing,Ty pe.Missing, Type.Missing);
// *** get the collection of sheets in the workbook
Excel.Sheets sheets = theWorkbook.Wor ksheets;
// *** get the first and only worksheet from the collection of worksheets
Excel.Worksheet worksheet = (Excel.Workshee t)sheets.get_It em(1);
....
}
=============== =============== =============== =============== ===

concerning the primary interop assemblies, under VS.Net I choose project>add
a reference>COM and then I select "Microsoft Excel 9 Object Librairy",
filename is "excel9.olb " ; it puts the interop.excel.d ll and
interop.office. dll in my project folder... I have problem to understand the
what is Interop...

Thanks for your help
_______________ _______________ _______________ _______________ _________
"Morten Wennevik" <Mo************ @hotmail.com> a écrit dans le message de
news: oprxs3y0dbhntkf z@localhost...
It might help if you would post some code of the problem.
My guess is that what you are trying to send to excel isn't something
excel can handle.
Not sure what changing cultureinfo would fix. Then again, some code would
be helpful.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #6
> // *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbo oks.Open(

"c:\counter.xls ",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlPlatfor m.xlWindows,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

Something among these paramteres is of the wrong type, but I couldn't find
much reference to WoorkBooks.Open in my helpfiles or MSDN, so I'm not sure
what it expects.

http://www.dotnet247.com/247referenc...22/113113.aspx
used this method to open a woorkbook

Excel.Workbook Workbook = objExcel.Workbo oks.Open(
ImportFileName,
0,
true,
5,
"",
"",
true,
Excel.XlPlatfor m.xlWindows,
"\t",
false,
false,
0,
false);
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #7
I already try all possibilities but nothing works... I don't know if this is
the code but maybe it comes from the interops ??
"Morten Wennevik" <Mo************ @hotmail.com> a écrit dans le message de
news: oprxs6x0wehntkf z@localhost...
// *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbo oks.Open(

"c:\counter.xls ",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlPlatfor m.xlWindows,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

Something among these paramteres is of the wrong type, but I couldn't find
much reference to WoorkBooks.Open in my helpfiles or MSDN, so I'm not sure
what it expects.

http://www.dotnet247.com/247referenc...22/113113.aspx
used this method to open a woorkbook

Excel.Workbook Workbook = objExcel.Workbo oks.Open(
ImportFileName,
0,
true,
5,
"",
"",
true,
Excel.XlPlatfor m.xlWindows,
"\t",
false,
false,
0,
false);
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3700
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox Matter matters= v.Matters; comboBox1.Items.AddRange(matters);
1
4905
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
4
2664
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am receiving these hidden values like the following:
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> System.InvalidCastException: Specified...
1
18206
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it is serialized correctly, and the server returns a response (I've captured the response and it's correct!) but when the .NET deserialize this response, it throws the exception "System.InvalidOperationException: There is an error in XML
2
13595
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) { this.Url = url;
1
5166
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out why i'm getting these errors! SO i have come here for the Help from the GURUS! here is one message that pops up! See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. **************...
8
4272
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is not valid"). How do I fix it ? using System.Diagnostics; .. .. class NewProcess: Process {
8
5776
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i trying to collect windows services. i'm getting inconsistencies. the collection works every time locally. but remote collection yields different result depending on my lab environment. 1) in the same domain i start the collection on the remote machine i can get some 19 services without a problem then it will fail with: 'wmiService.ClassPath' threw an exception of type 'System.InvalidCastException'
4
1847
by: rsdev | last post by:
Hi, I have an InvalidCastException which is completely puzzling me. I have checked all the members in the stored procedure against my data provider and seems to be ok. Also in the stack trace it says ProcessRequestMain... +3742?? Here's the error; Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.