By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Arraylist Copyto() InvalidCastException

P: n/a
Hello All:
Having a problem with arraylist.copyto 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.pointarray = new global.point[global.myal.Count];
global.myal.Copyto(pointarray);
for (i=0; i<global.myal.count; i++)
{
a = pointarray[i].x;
b = pointarray[i].y;

}
global.myal.Clear();
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.Copyto(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
Share this Question
Share on Google+
3 Replies


P: n/a
pe******@yahoo.com wrote:
in Main function -->
global.pointarray = new global.point[global.myal.Count];
global.myal.Copyto(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.Copyto(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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.