FileGet overload resolution

snarfblam

Mega-Ultra Chicken
Joined
Jun 10, 2003
Messages
1,832
Location
USA
User Rank
*Expert*
I have ported a VB6 program to VB.NET. The program needs to read blocks of bytes from a file. Here is an example of the sort of code I use in many places in the file:
[VB]
FileGet(FileNumber, GameText)
[/VB]
GameText is a one dimensional array of bytes. This works fine with option strict off. When I turn option strict on there is, quite understandably, an overload resolution failure. I tried casting GameText to a System.Array and instead of reading the data, the array I got was the unmodified array filled with zeros. I tried casting to an object and got a security error(?). I dont know which overload is being called but it must be FileGet(Integer, System.Array, [Integer]) or FileGet(Integer, Object, [Integer]). I would think the first which accepts an array.

I dont see how, but could the casting to type System.Array cause a problem with the ByRef argument (the array that I am passing)?
Am I wrong in expecting the first overload i mentioned to be the one that is called?
Can somebody please help me?

BTW: I would change it over to the filestream class but I am more familiar with the old vb6 way and more importantly there is a lot of code involved that would have to be changed. It is not out of the question but I would certainly rather not change all that code.

[Edit]The security error only happened once. Casting to an object seems to have the same effect as casting to an array.[/Edit]
 
Last edited by a moderator:
Well, Ive started converting my program over to filestreams and it looks like I only have about 100 fileget/fileputs left to replace, but just in case anyone who knows the answer to the above question, I am still very curious.
 
Back
Top