Results 1 to 10 of 10

Thread: Error Messages "Error 1" Type namespace could not be .....

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    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

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Error Messages "Error 1" Type namespace could not be .....

    hmmm Tried the using on the Form didnt fix it

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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:
    1. Imports System.Net.Sockets
    2. Imports System.IO
    3. Imports System.Text
    4.  
    5. Public Class TCPConnection
    6.  
    7.     Public Event DataArrived(ByVal Data() As Byte)
    8.     Public Event Disconnected()
    9.  
    10.     Private Const READ_BUFFER_SIZE As Integer = 255
    11.  
    12.     Private _ReadCallBack As AsyncCallback
    13.  
    14.     Private _HostAddress As String
    15.     Private _Port As Integer
    16.  
    17.     Private _TCPClient As TcpClient
    18.  
    19.     Private _NS As NetworkStream
    20.     Private _SW As StreamWriter
    21.  
    22.     Private _Buffer(READ_BUFFER_SIZE - 1) As Byte
    23.  
    24.     Private Delegate Sub RaiseReceiveEvent(ByVal Data() As Byte)
    25.     Private _SyncObject As System.ComponentModel.ISynchronizeInvoke
    26.  
    27.     Public Sub New(ByRef SyncObject As System.ComponentModel.ISynchronizeInvoke, ByVal HostAddress As String, ByVal Port As Integer)
    28.         _SyncObject = SyncObject
    29.         _HostAddress = HostAddress
    30.         _Port = Port
    31.         Connect()
    32.     End Sub
    33.  
    34.     Public ReadOnly Property HostAddress() As String
    35.         Get
    36.             Return _HostAddress
    37.         End Get
    38.     End Property
    39.  
    40.     Public ReadOnly Property Port() As Integer
    41.         Get
    42.             Return _Port
    43.         End Get
    44.     End Property
    45.  
    46.     Public Sub Connect()
    47.         _TCPClient = New TcpClient(_HostAddress, _Port)
    48.         _NS = _TCPClient.GetStream()
    49.         _SW = New StreamWriter(_NS, Encoding.ASCII)
    50.         _SW.AutoFlush = True
    51.         StartAsyncRead()
    52.     End Sub
    53.  
    54.     Public Sub Disconnect()
    55.         If Not (_TCPClient Is Nothing) Then
    56.             _TCPClient.Close()
    57.             _TCPClient = Nothing
    58.         End If
    59.         RaiseEvent Disconnected()
    60.     End Sub
    61.  
    62.     Public Sub SendData(ByRef Data As String)
    63.         _SW.Write(Data)
    64.     End Sub
    65.  
    66.     Private Sub StartAsyncRead()
    67.         _ReadCallBack = New AsyncCallback(AddressOf DoRead)
    68.         _NS.BeginRead(_Buffer, 0, READ_BUFFER_SIZE, _ReadCallBack, Nothing)
    69.     End Sub
    70.  
    71.     Private Sub DoRead(ByVal Result As IAsyncResult)
    72.         Try
    73.             Dim BytesRead As Integer = _NS.EndRead(Result)
    74.  
    75.             If BytesRead < 1 Then
    76.                 Disconnect()
    77.             Else
    78.                 Dim Data(BytesRead - 1) As Byte
    79.                 _Buffer.Copy(_Buffer, 0, Data, 0, BytesRead)
    80.  
    81.                 Dim Args(0) As Object
    82.                 Args(0) = Data
    83.  
    84.                 Dim NewDelegate As New RaiseReceiveEvent(AddressOf OnReceive)
    85.                 _SyncObject.Invoke(NewDelegate, Args)
    86.  
    87.                 StartAsyncRead()
    88.             End If
    89.         Catch Ex As Exception
    90.             Disconnect()
    91.         End Try
    92.     End Sub
    93.  
    94.     Private Sub OnReceive(ByVal Data() As Byte)
    95.         RaiseEvent DataArrived(Data)
    96.     End Sub
    97. 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

  6. #6

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    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..

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Error Messages "Error 1" Type namespace could not be .....

    I'll give that a shot..

  9. #9

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    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??

  10. #10
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width