473,830 Members | 2,120 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 2539
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
5747
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
5990
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
8344
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
4330
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
1823
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
3588
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
2475
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
15953
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
9781
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
9641
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
10769
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...
1
10522
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
10197
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
9310
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
5615
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
4408
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
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.