This project has moved and is read-only. For the latest updates, please go here.

Vb.net code problem.

Sep 24, 2016 at 7:38 PM
Edited Sep 24, 2016 at 8:11 PM
This vb.net code not working. What is problem. Please help me.


Sub Main()
    Using server As New DnsServer(10, 10)
        AddHandler server.QueryReceived, AddressOf OnQueryReceived
        server.Start()


        Console.WriteLine("Press any key to stop server")
        Console.ReadLine()
    End Using
End Sub



Private Function OnQueryReceived(sender As Object, e As QueryReceivedEventArgs) As Task

        Dim query As DnsMessage = TryCast(e.Query, DnsMessage)

        If query Is Nothing Then
            Return Nothing
        End If

        Dim response As DnsMessage = query.CreateResponseInstance()




        ' check for valid query



        If (query.Questions.Count = 1) AndAlso (query.Questions(0).RecordType = RecordType.Any) AndAlso (query.Questions(0).Name.Equals(DomainName.Parse("altinsoft.com"))) Then


            response.ReturnCode = ReturnCode.NoError


            response.AnswerRecords.Add(New ARecord(DomainName.Parse("altinsoft.com"), 3600, IPAddress.Parse("127.0.1.22")))

        Else
            response.ReturnCode = ReturnCode.NxDomain
        End If

        ' set the response
        e.Response = response

 End Function

Error Message :

DNS_Server_test.vshost.exe Error: 0 : Exception in DnsServer: System.ArgumentException: Tasks argument contained a null value.

Parameter name: tasks
location: System.Threading.Tasks.Task.WhenAll(IEnumerable1 tasks)
location: ARSoft.Tools.Net.AsyncEventHandlerExtensions.RaiseAsync[T](AsyncEventHandler
1 eventHandler, Object sender, T eventArgs)
location: ARSoft.Tools.Net.Dns.DnsServer.<ProcessMessageAsync>d__22.MoveNext()
--- Starting position before the end of the stack trace where the exception was created ---
location: System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
location: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
location: System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
location: ARSoft.Tools.Net.Dns.DnsServer.<HandleUdpListenerAsync>d__24.MoveNext()