What do I need to do to reference the System.Net and System.Net.Sockets namespaces ? I can see them in a class browser nesting under the System namespace, but
Imports System
Imports System.Net
doesn't seem to be sufficient/correct...? Do I need to do something to the GAC to make them
available ? Is there a way of promoting these nested namespaces to the root level of the GAC ? (I'm guessing the namespaces will be found then...) or...... something else.....?
Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Client
Public Shared Sub Main()
Dim tcpc as new System.Net.Sockets.TCPClient()
Dim read(35) as byte
Dim args as string() = Environment.GetCommandLineArgs()
If (args.length < 2) then
console.writeline("Please specify a server name in the command line")
exit sub
end if
Dim server as string = args(1)
'Verfiy that server exists
Try
DNS.GetHostByName(server)
Catch
console.writeline("Cannot find server: {0}", server)
exit sub
End Try
'Try to connect to the server
Try
tcpc.Connect(server, 13)
Catch exc as SocketException
console.writeline("Cannot connect to {0}: {1}", server, exc.Message)
exit sub
End Try
console.writeline("Successful connection to {0}", server)
tcpc.close()
End Sub
End Class
then from the command-line : vbc c:\client.vb resulting in: Microsoft (R) Visual Basic .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322.573 Copyright (C) Microsoft Corporation
1987-2002. All rights reserved. c:\Client.vb(6) : error BC30466: Namespace or type 'Net' for the Imports 'System .Net' cannot be found. Imports System.Net ~~~~~~~~~~ c:\Client.vb(7) : error BC30466: Namespace or type 'Sockets' for the Imports 'Sy stem.Net.Sockets'
cannot be found. Imports System.Net.Sockets ~~~~~~~~~~~~~~~~~~ c:\Client.vb(13) : error BC30002: Type 'System.Net.Sockets.TCPClient' is not def ined. Dim tcpc as new System.Net.Sockets.TCPClient() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c:\Client.vb(26) : error BC30451:
Name 'DNS' is not declared. DNS.GetHostByName(server) ~~~ c:\Client.vb(35) : error BC30002: Type 'SocketException' is not defined. Catch exc as SocketException ~~~~~~~~~~~~~~~
Oh I see, you should add a reference to the System.Net.dll assembly using the /r flag in the vbc.ee compiler syntax. vbc.exe /r:System.Net.dll source.vb Make sure the System.Net.dll assembly can be found through the PATH in your environment (should be ok if
you're able to run vbc.exe)
Thanks for your help Bart. I do not have the System.Net.Dll file anywhere on my PC. But, as I say, it IS visible under the system namespace.... If I try using the r:System.Net.dll I get: Microsoft (R) Visual Basic .NET Compiler version 7.10.3052.4 for Microsoft
(R) .NET Framework version 1.1.4322.573 Copyright (C) Microsoft Corporation 1987-2002. All rights reserved. vbc : Command line error BC2017 : could not find library 'System.Net.Dll' vbc : Fatal error BC2000 : compiler initialization failed unexpectedly: The
system cannot find the file specified.
using System
using System.Net
using System.Net.Sockets
such as the WinTalk.cs sample file from the SDK is compiled using csc c:\wintalk.cs It compiles right off, with no problem finding the System.Net and .Sockets namespaces The only difference between the two compilers'
parameters is that the csharp compiler has an additional warningLevel="1" in machine.config
Varples
Member
95 Points
19 Posts
vb.net referencing the System.Net namespace
Nov 26, 2003 07:26 AM|LINK
bdesmet
Star
8255 Points
1651 Posts
Re: vb.net referencing the System.Net namespace
Nov 26, 2003 07:33 AM|LINK
Visit www.msdn.be, www.bartdesmet.net
Varples
Member
95 Points
19 Posts
Re: vb.net referencing the System.Net namespace
Nov 26, 2003 07:40 AM|LINK
Imports System Imports System.IO Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class Client Public Shared Sub Main() Dim tcpc as new System.Net.Sockets.TCPClient() Dim read(35) as byte Dim args as string() = Environment.GetCommandLineArgs() If (args.length < 2) then console.writeline("Please specify a server name in the command line") exit sub end if Dim server as string = args(1) 'Verfiy that server exists Try DNS.GetHostByName(server) Catch console.writeline("Cannot find server: {0}", server) exit sub End Try 'Try to connect to the server Try tcpc.Connect(server, 13) Catch exc as SocketException console.writeline("Cannot connect to {0}: {1}", server, exc.Message) exit sub End Try console.writeline("Successful connection to {0}", server) tcpc.close() End Sub End Classthen from the command-line : vbc c:\client.vb resulting in: Microsoft (R) Visual Basic .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322.573 Copyright (C) Microsoft Corporation 1987-2002. All rights reserved. c:\Client.vb(6) : error BC30466: Namespace or type 'Net' for the Imports 'System .Net' cannot be found. Imports System.Net ~~~~~~~~~~ c:\Client.vb(7) : error BC30466: Namespace or type 'Sockets' for the Imports 'Sy stem.Net.Sockets' cannot be found. Imports System.Net.Sockets ~~~~~~~~~~~~~~~~~~ c:\Client.vb(13) : error BC30002: Type 'System.Net.Sockets.TCPClient' is not def ined. Dim tcpc as new System.Net.Sockets.TCPClient() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c:\Client.vb(26) : error BC30451: Name 'DNS' is not declared. DNS.GetHostByName(server) ~~~ c:\Client.vb(35) : error BC30002: Type 'SocketException' is not defined. Catch exc as SocketException ~~~~~~~~~~~~~~~bdesmet
Star
8255 Points
1651 Posts
Re: vb.net referencing the System.Net namespace
Nov 26, 2003 07:48 AM|LINK
Visit www.msdn.be, www.bartdesmet.net
Varples
Member
95 Points
19 Posts
Re: vb.net referencing the System.Net namespace
Nov 26, 2003 08:13 AM|LINK
Varples
Member
95 Points
19 Posts
Re: vb.net referencing the System.Net namespace
Nov 26, 2003 09:20 AM|LINK