Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# with asp.net, Ping utlity

Status
Not open for further replies.

BoostMR2

IS-IT--Management
Jul 20, 2007
33
US
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?
 
it doesn;t appear to be. It's a member of the System class, does it need to be instantiated anyways? The example code doesn't do this.
 
Update: it appears that any method i try to use from Buffer gives the same exact error. I tried a simple Buffer.ByteLength(data) and gave same exact error.

Every example i look at online, even from MSDN, uses Buffer as if it's included. I made sure i have "Using System" as well, and it's running from the 2.0 framework.

Update: I found out the problem, kind of. I have included a "Using System;" at the top of my page. Then i have a namespace, a class, and methods. For some reason, it does not find Buffer. I added System.Buffer.<method> and it worked! But why? Why doesn;t it work as it should with "Using System;"?
 
two classes with the same name in different namespaces can cause an issue if they are referenced in the same code. To correct this either a namespace alias, or full namespaces must be used to distinguish the object.
Code:
System.Buffer.Function();
MyNameSpace.Buffer.Function();
or
using S = System;
using M = MyNameSpace;
S.Buffer.Function();
M.Buffer.Function();

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top