473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

"cannot apply indexing with [] to an expression of type object"

Hi,

I get an error "cannot apply indexing with [] to an expression of type
object" when I try to compile the code below.

SSLScannerManager is a COM component. (Used to access fingerprint
scanners and developed by neurotechnologija)

How does one get an array from a com component?
private void loadScanners()
{
SSLScannerMan scanMan = new SSLScannerMan();
scanMan.Initialize();
try
{
Int32 lenght = scanMan.DeviceCount;
object ids = new String[lenght];
scanMan.EnumDeviceIDs(ref ids);
scanners.Items.Clear();
for (Int32 i = 0; i < ((Array)ids).Length; i++)
{
String strTemp = (string) ((object)ids)[i]; // ERROR HERE
scanners.Items.Add(strTemp);
}

if (Scanner != null)
{
selected.Text = Scanner.DeviceID;
}
else
{
selected.Text = "N/A";
}
}
finally
{
scanMan.Finalize();
releaseComObject(scanMan);
}
}
Nov 17 '05 #1
3 14312
String strTemp = (string) ((string[])ids)[i];

Should resolve it - you were trying to index into an object whereas the object is actually a string array - so you can cast it to that.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I get an error "cannot apply indexing with [] to an expression of type
object" when I try to compile the code below.

SSLScannerManager is a COM component. (Used to access fingerprint
scanners and developed by neurotechnologija)

How does one get an array from a com component?
private void loadScanners()
{
SSLScannerMan scanMan = new SSLScannerMan();
scanMan.Initialize();
try
{
Int32 lenght = scanMan.DeviceCount;
object ids = new String[lenght];
scanMan.EnumDeviceIDs(ref ids);
scanners.Items.Clear();
for (Int32 i = 0; i < ((Array)ids).Length; i++)
{
String strTemp = (string) ((object)ids)[i]; // ERROR HERE
scanners.Items.Add(strTemp);
}

if (Scanner != null)
{
selected.Text = Scanner.DeviceID;
}
else
{
selected.Text = "N/A";
}
}
finally
{
scanMan.Finalize();
releaseComObject(scanMan);
}
}

[microsoft.public.dotnet.languages.csharp]
Nov 17 '05 #2


Thanks for the quick answer.

When I cast to string[] I get a "Cast is not valid exception" at
runtime.

I guess it is not returning a string. Te VB example used a string

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
Karel Vandenhove <ka*************@yahoo.com> wrote:
Thanks for the quick answer.

When I cast to string[] I get a "Cast is not valid exception" at
runtime.

I guess it is not returning a string. Te VB example used a string


Print out ids.GetType() to find out what type it is, and then use that
as the cast.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
3
by: Jason luo | last post by:
Hi all, In c99-standard page 52,there is a sentence about void,as below: If an expression of any other type is evaluated as a void expression, its value or designator is discarded. I don't...
1
by: Dgates | last post by:
This request might belong in a "SQL"-related newsgroup, but it's such a pain using Agent to subscribe to a new group (and download its 50,000 messages!) just to ask one question. So, since it...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
4
by: =?Utf-8?B?SmFu?= | last post by:
In my application the user can configure automation-scripts by inserting different "actions" into a "procedure". These different procedure- and action-objects are all translated into C# code before...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.