operation is not supported

vgopalap

Member
Joined
Dec 27, 2011
Messages
6
Programming Experience
Beginner
I have a little bit different problem Iam able to get the main form but when I try to go online I get a message Socket exceptioin was unhandled (The attempted operation is not supported for the type of object referenced) message. below is the code where Iam getting error. Please suggest where Am I going wrong.
Private Sub SetBcastAddress(ByVal Iface As Integer, ByVal Addr As System.Net.IPAddress)
        Dim netIF As System.Net.NetworkInformation.NetworkInterface() = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
        Dim myIP As System.Net.NetworkInformation.UnicastIPAddressInformation
        Dim ipProp As System.Net.NetworkInformation.IPInterfaceProperties
        Dim myIPCol As System.Net.NetworkInformation.UnicastIPAddressInformationCollection
        ipProp = netIF(Iface).GetIPProperties()
        myIPCol = ipProp.UnicastAddresses()
        Dim lIP As UInt32
        Dim lMask As UInt32
        Dim lBcast As UInt32
        For Each myIP In myIPCol
            Dim netmask As System.Net.IPAddress
            netmask = myIP.IPv4Mask
            If netmask Is Nothing Then
                bcastAddr = System.Net.IPAddress.Parse("172.18.1.162")
                Exit Sub
            End If
            lIP = Addr.Address
            lMask = netmask.Address
            lBcast = lIP Or (Not lMask)
            bcastAddr = New System.Net.IPAddress(lBcast)
            Exit Sub
        Next myIP
    End Sub
 
Last edited by a moderator:
Hello jmcilhinney,

Exactly Iam getting the error at the below lines.
lIP = Addr.Address
lMask = netmask.Address

Thanks for responding immediately.
 
That property throws that exception for IPv6 networks, but before that happened you should have noticed this:

This is what compiler warning tells you:
This property has been deprecated. It is address family dependent.
This is what documentation for Address Property says:
This property is obsolete. Use GetAddressBytes method.
You have to check IpAddress.AddressFamily for InterNetwork before attempting to perform IPv4 operations. For IPv6 broadcast is address ff02::1.
 

Similar threads

Back
Top