Error Messages "Error 1" Type namespace could not be .....
Ok This post carries on from the Last Errors where WokeWidget helped with his TCPConnection Code.....
I'm getting 2 Errors and here they are::
Code:
Error 1 The type or namespace name 'SocketDataArrival' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\jerry\My Documents\Visual Studio 2005\Projects\DemonBytes\DemonBytes\TCPConnection.cs 6 18 DemonBytes
Error 2 The type or namespace name 'DisconnectedEventHandler' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\jerry\My Documents\Visual Studio 2005\Projects\DemonBytes\DemonBytes\TCPConnection.cs 7 18 DemonBytes
Both the Errors are on the same .cs file Named TCPConnection.cs
Here is the Code::
Code:
public class TCPConnection
{
public event SocketDataArrival.EventHandler DataArrived;
public event DisconnectedEventHandler Disconnected;
private const int READ_BUFFER_SIZE = 255;
private System.AsyncCallback _ReadCallBack;
private string _HostAddress;
private int _Port;
private TcpClient _TCPClient;
private NetworkStream _NS;
private StreamWriter _SW;
private byte[] _Buffer = new byte[READ_BUFFER_SIZE - 1];
private delegate void RaiseReceiveEvent(byte[] Data);
private System.ComponentModel.ISynchronizeInvoke _SyncObject;
Now the SocketDataArrival is Underlined in a Blue Siggly Line along with DisconnectedEventHandler...
That is just some of the Code WokaWidget gave me which you can find in my last Post for Help....The Code is on its own .cs file, and in the Form Body when i type TCPConnection the Drop Down Box appears for the IntelliSence allowing me too Choose it..
I have used the TCPConnection in a few places here they are::
Code:
private void Socket_DataArrival(object eventSender, TCPConnection eventArgs)
{ ....} // Cut the code Short
private void Socket_Error(object eventSender, TCPConnection eventArgs)
{
short Index = Socket.GetIndex(eventSender);
toolStripStatusLabel1.Text = "Status: Error";
Socket(Index).Close();
}
private void Timer1_Tick(object eventSender, System.EventArgs eventArgs)
{
short i;
for (int i = 0; i <= System.Convert.ToDouble(BotsList.Text) - 1; i++)
{
PacketsLabel.Text = System.Convert.ToString(System.Convert.ToDouble(PacketsLabel.Text) + 1);
if (Socket(i).CtlState == TCPConnection)
The Section of Code i didnt Introduce because i didnt know where it was suppose to fit into my Code
Code:
private TCPConnection _TCPConn;
private bool Connect(string HostName, int Port)
{
_TCPConn = new TCPLibrary.TCPConnection(this, HostName, Port);
}
private void _TCPConn_DataArrived(byte[] Data)
{
string DataString = System.Text.Encoding.ASCII.GetString(Data, 0, Data.GetLength(0));
DataArrived(DataString);
}
Any and all help on this Issue will be Greatly Appreciated Thxs..Rattlerr ;)
Re: Error Messages "Error 1" Type namespace could not be .....
err...that's because the event is probably setup wrong.
Do you know how do deal with even simple events in simple classes?
I still haven't had toime do do anything with this yet.
Not back in England until Saturday, where I will be sleeping off my jedt lack.
All my time has been devoted to using MPS along side C# aqnd Active Directory :(
New job...new pressures...no time to develop my own stuff :(
Woka
Re: Error Messages "Error 1" Type namespace could not be .....
The two likely reasons for this are exactly as the error message says. Either you have not added a reference to the assembly in which the type is defined or else you are trying to use the type name unqualified without importing its namespace with a 'using' statement at the top of your code file.
Edit: I guess another possibility is that the type just doesn't exist, but that really falls under the first one above. There exists no reference to an assembly in which the type is defined.
Re: Error Messages "Error 1" Type namespace could not be .....
hmmm Tried the using on the Form didnt fix it
Re: Error Messages "Error 1" Type namespace could not be .....
This code I sent you the other day was not working code, it was meant as a guide to point you in the right direction.
It was converted from VB.NET code that I wrote, and use:
VB Code:
Imports System.Net.Sockets
Imports System.IO
Imports System.Text
Public Class TCPConnection
Public Event DataArrived(ByVal Data() As Byte)
Public Event Disconnected()
Private Const READ_BUFFER_SIZE As Integer = 255
Private _ReadCallBack As AsyncCallback
Private _HostAddress As String
Private _Port As Integer
Private _TCPClient As TcpClient
Private _NS As NetworkStream
Private _SW As StreamWriter
Private _Buffer(READ_BUFFER_SIZE - 1) As Byte
Private Delegate Sub RaiseReceiveEvent(ByVal Data() As Byte)
Private _SyncObject As System.ComponentModel.ISynchronizeInvoke
Public Sub New(ByRef SyncObject As System.ComponentModel.ISynchronizeInvoke, ByVal HostAddress As String, ByVal Port As Integer)
_SyncObject = SyncObject
_HostAddress = HostAddress
_Port = Port
Connect()
End Sub
Public ReadOnly Property HostAddress() As String
Get
Return _HostAddress
End Get
End Property
Public ReadOnly Property Port() As Integer
Get
Return _Port
End Get
End Property
Public Sub Connect()
_TCPClient = New TcpClient(_HostAddress, _Port)
_NS = _TCPClient.GetStream()
_SW = New StreamWriter(_NS, Encoding.ASCII)
_SW.AutoFlush = True
StartAsyncRead()
End Sub
Public Sub Disconnect()
If Not (_TCPClient Is Nothing) Then
_TCPClient.Close()
_TCPClient = Nothing
End If
RaiseEvent Disconnected()
End Sub
Public Sub SendData(ByRef Data As String)
_SW.Write(Data)
End Sub
Private Sub StartAsyncRead()
_ReadCallBack = New AsyncCallback(AddressOf DoRead)
_NS.BeginRead(_Buffer, 0, READ_BUFFER_SIZE, _ReadCallBack, Nothing)
End Sub
Private Sub DoRead(ByVal Result As IAsyncResult)
Try
Dim BytesRead As Integer = _NS.EndRead(Result)
If BytesRead < 1 Then
Disconnect()
Else
Dim Data(BytesRead - 1) As Byte
_Buffer.Copy(_Buffer, 0, Data, 0, BytesRead)
Dim Args(0) As Object
Args(0) = Data
Dim NewDelegate As New RaiseReceiveEvent(AddressOf OnReceive)
_SyncObject.Invoke(NewDelegate, Args)
StartAsyncRead()
End If
Catch Ex As Exception
Disconnect()
End Try
End Sub
Private Sub OnReceive(ByVal Data() As Byte)
RaiseEvent DataArrived(Data)
End Sub
End Class
Which works perfectly.
I have not used the c# version as of yet, nor have I tested it.
WHat you can do is look on the interweb and find out about how to handle events in c#.
Just adding something to the form ain't gonna work.
Code:
public event SocketDataArrival.EventHandler DataArrived;
Clearly the TCPClient object in VB.NET has events as you can see.
Now...all you need to find out is how to handle these events in C#. Do a search for "C# TCPClient" on the web and I'm sure it will show u exactly what to do.
Woka
Re: Error Messages "Error 1" Type namespace could not be .....
I'll look again believe me I'v referenced it on the MSDN that came with the program and they Lack any kind of useful help most of the time...
I do some more Research but so far not much as turned up that i havent tried..
Re: Error Messages "Error 1" Type namespace could not be .....
you cud always compile the VB.NET code and then reference that in you C# project ;)
Woka
Re: Error Messages "Error 1" Type namespace could not be .....
Re: Error Messages "Error 1" Type namespace could not be .....
Code:
#region API Declaration
[System.Runtime.InteropServices.DllImport("TCPConnection.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
#endregion
Is this Correct??
Re: Error Messages "Error 1" Type namespace could not be .....
Quote:
Originally Posted by Rattlerr
Code:
#region API Declaration
[System.Runtime.InteropServices.DllImport("TCPConnection.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
#endregion
Is this Correct??
You can see yourself if this is correct or incorrect by just compiling the project.
I don't see anything wrong in the declaration.