473,938 Members | 33,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arraylist Copyto() InvalidCastExce ption

Hello All:
Having a problem with arraylist.copyt o function. And here's a
sample of my code in C#:
In global-->
public struct point
{
int x;
string y;

}
static public point point;
static public point pointarray[];
static public Arraylist myal = new Arraylist();

in sub_function -->
for (i=0; i< some limites; i++)
{
global.point[i].x = some limites.some value;
global.point[i].y = some limites.some string;
global.myal.Add (global.point);

}
in Main function -->

int a;
string b;
global.pointarr ay = new global.point[global.myal.Cou nt];
global.myal.Cop yto(pointarray) ;
for (i=0; i<global.myal.c ount; i++)
{
a = pointarray[i].x;
b = pointarray[i].y;

}
global.myal.Cle ar();
pointarray = null;

This is basically the logic of the steps that I am trying to make a
dynamic array struct, of course I understand there are different ways
of doing this, but this one seems easiest if I was to pick and choose
what needed to be inserted into my arraylist in main / sub function. It

works fine on my computer (xp pro .net 2.0), however it doesn't work on

my company's server computer (running server2003.net 2.0) Saying there
there is a casting exception on the global.myal.Cop yto(pointarray)
statement. I spend a lot of time trying to understand why this differ
from machine to machine. But came up with nothing in MSDN or other
resources. Have anyone done something like this? Please let me know!!
Thank You!
Also, it keep on telling me that I have a casting problem, so I tried
to explicitly cast the array out of arraylist instead of copyto()..
Doesn't work either. Any ideas how to do that? Very much appreciated
it!!

Aug 29 '06 #1
3 2548
pe******@yahoo. com wrote:
in Main function -->
global.pointarr ay = new global.point[global.myal.Cou nt];
global.myal.Cop yto(pointarray) ;
works fine on my computer (xp pro .net 2.0), however it doesn't work on
my company's server computer (running server2003.net 2.0) Saying there
there is a casting exception on the global.myal.Cop yto(pointarray)
statement.
Are the main method and the global class (struct?) in the same
assembly? Or is "global" in a library? If the latter, is it possible
that there is a version mismatch between what you're compiling with
and testing against on your development machine and what you're using
at runtime on the server?

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 29 '06 #2
Sorry to say, I am not sure what do you mean. It's in the same C#
project file? It's not from another DLL or calling another class! Is
that same Assembly?

Aug 30 '06 #3
pe******@yahoo. com wrote:
Sorry to say, I am not sure what do you mean. It's in the same C#
project file? It's not from another DLL or calling another class! Is
that same Assembly?
Yes, though I feel sort of obliged to point out that, in general,
you're not going to get much response to such very basic questions.
Few people are going to take the time to answer something that you
could easily Google, or answer via the VS help system, or even by
checking the index of just about any basic .NET book. For example, I'm
only answering that because I tried to answer your original query.

To get back to that, if it's not some sort of version mismatch, I'm
not really sure why it would run on your development system and not on
a server. It might help if you posted compilable code, not your
snippets.

One other possibility is that you compiled under 2.0, and the server
only has 1.1 installed ... or vice versa. This shouldn't give the
error you see, though ....

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 30 '06 #4

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

Similar topics

1
597
by: Mortimer Schnurd | last post by:
Has anyone had any luck getting this CopyTo method to work? I can iterate through a MatchCollection and move each Match.Value to the System.Array without a problem. I just can't figure out why the CopyTo method will not work. Example: // Find all the Tables in an html string (page) MatchCollection mc = Regex.Matches(html, "<table.+</table"); string t = new string;
1
5755
by: Craig | last post by:
Hey Everyone - I'm trying to determine the fastest way of moving array information around and could use some help. Here's the setup: Class A stores a DateTime and an amount (a payment). Class B is functionally an array of A objects (representing a cashflow). Class C is functionally an array of B objects (representing an organization of cashflows).
20
6000
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
15
8357
by: Sam | last post by:
Hi, I have the following code : Dim rNodeList As New ArrayList Dim rNodeListNew As New ArrayList For iCntr As Integer = 0 To tvRelations.Nodes.Count - 1 rNodeList.Add(tvRelations.Nodes(iCntr).Text) Next
6
4345
by: Desmond Cassidy | last post by:
Hi, I'm sure this has been asked several times before but I'll risk it ;-) If I wish to save an Arraylist to another Arraylist and work on te original without affecting the contents of the new or saved Arraylist, how is it done. It always seems to create a shallow copy i.e. by Reference. I even tried passing the original Arraylist to a function by Value and return a copy....after an arraylist.clear on the original it still clears the...
6
1832
by: Iapain | last post by:
Hello, I've created an arraylist which consist arraylist ..like ArrayList myAL = new ArrayList(); // Main Array List ArrayList tmpAL = new ArrayList(); //Temp Array List tmpAL.Add(2); //Add int to Temp AL tmpAL.Add(3); //Add int to Temp AL myAL.Add(tmpAL); //Add Temp AL to Main AL //(and so on)
2
3603
by: pengbsam | last post by:
Hello All: Having a problem with arraylist.copyto function. And here's a sample of my code: In global--> public struct point { int x; string y; } static public point point;
5
2481
by: tshad | last post by:
How do you easily make a copy of an arraylist? If you do: arrayList2 = arrayList1 You get a pointer so that if you clear arrayList2 (arrayList2.Clear) - arrayList1 is also cleared. I want to create a copy of the arrayList, which I can do looping through the
22
15983
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b = (ArrayList) a.Clone();
0
10126
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
11099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11282
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10652
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
9854
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
8209
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
7377
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
6072
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...
3
3495
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.