C# .NET - C# Buffer.BlockCopy - Asked By Chris Wofford on 20-Jul-07 09:30 AM

I am trying some example Ping utilities as an asp.net application.  The example I am trying to use is from http://www.java2s.com/Code/CSharp/Network/SimplePing.htm

I am new to C#, and believe I am missing something.  The following portion of the code builds the message body of the packet to be sent.  During compilation, it throws the error.

Buffer.BlockCopy(BitConverter.GetBytes((short)1), 0, packet.Message, 0, 2);

CS0117: 'bool' does not contain a definition for 'BlockCopy'

I cannot see why the compiler thinks I am passing any boolean value as an argument to BlockCopy.  (short)1 makes an int16, GetBytes creates an array[16] of bytes, and the other 4 arguments are standard.  Am I missing something?

Found another line of code that does it as well, same function, same error

Buffer.BlockCopy(data, 0, packet.Message, 4, data.Length);

note: data is an Array of bytes, just as before

Ben Biddington replied to Chris Wofford on 20-Jul-07 12:06 PM
Doesn't that message imply you're trying to invoke BlockCopy on a Boolean? Like for example you have a Boolean variable named Buffer.

Not enough sample code in your post to tell what is going on... - Peter Bromberg replied to Chris Wofford on 20-Jul-07 11:37 AM

Try spelling out the fulll System namespace before Buffer.

Parameters

src

The source buffer.

srcOffset

The byte offset into src.

dst

The destination buffer.

dstOffset

The byte offset into dst.

count

The number of bytes to copy.

Fixed - Chris Wofford replied to Ben Biddington on 23-Jul-07 02:12 PM

As it turns out, the fix is something I still do not understand.

I have "Using System;" at the top of my file

the path for this is System.Buffer.BlockCopy

For some reason, it didn;t work until I added this full path, even though I had an include for System.  I may have done someting wrong, but it works now.  I'm leaving it at that.

Ben Biddington replied to Chris Wofford on 24-Jul-07 02:43 AM
I reckon do a solution-wide search for Buffer - you must have a property or variable in scope with that name.