473,597 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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.

SSLScannerManag er is a COM component. (Used to access fingerprint
scanners and developed by neurotechnologi ja)

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

if (Scanner != null)
{
selected.Text = Scanner.DeviceI D;
}
else
{
selected.Text = "N/A";
}
}
finally
{
scanMan.Finaliz e();
releaseComObjec t(scanMan);
}
}
Nov 17 '05 #1
3 14355
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.

SSLScannerManag er is a COM component. (Used to access fingerprint
scanners and developed by neurotechnologi ja)

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

if (Scanner != null)
{
selected.Text = Scanner.DeviceI D;
}
else
{
selected.Text = "N/A";
}
}
finally
{
scanMan.Finaliz e();
releaseComObjec t(scanMan);
}
}

[microsoft.publi c.dotnet.langua ges.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.co m>
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
3947
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 update database or object is read-only". This is a workstation machine, not connected to any other computer, and I login to the PC using an administrator account. I already check the .MDB file is NOT read-only. But, I do not see the .LDB file....
70
8853
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 expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
10
3710
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 bug? Can someone excellent to tell me the reason. best wishes
7
22719
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 and change it with other panel which contains other business logic and UI controls.
3
5677
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 know how to understand it, How to evaluate the expression as a void expression? explicit conversion the expression? but, befor the sentence ,"implicit or explicit conversions (except to void) shall not
1
1854
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 deals with an ASP.NET app, I thought I'd ask here. ============================================== I am using Web Data Adminstrator, which I downloaded recently from the Microsoft site. I get an error when I create tables or columns:
6
10659
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 data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
4
2741
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 execution. One "action" type is an expression-evaluator. At the moment the expression the user writes into the action is just inserted into the generated C# code unchanged. The problem is the variables in my system and in the "procedures";...
56
6696
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 6.4.2(2) : case constant-expression : I propose that the case expression of the switch statement be changed from "integral constant-expression" to "integral expression".
0
7959
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
8263
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8254
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
6677
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...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3876
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2393
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
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1226
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.