DotRAS.dll not working on Windows 10 Update 1803

1.3k Views Asked by At

I have a small VB.NET program, which creates a VPN connection. This is working until (and including) Windows 10 Update 1709. But since the Update 1803 I always get an exception:

DotRas.RasException: An incorrect structure size was detected. at DotRas.Internal.ThrowHelper.ThrowRasException(Int32 errorCode) at DotRas.Internal.RasHelper.GetEntryProperties(RasPhoneBook phoneBook, String entryName) at DotRas.RasEntryCollection.Load() at DotRas.RasPhoneBook.Open(String phoneBookPath)

Following my working Code Sub (until 1709)

Private Sub CreateVPN(VpnName As String, Destination As String, bAllUsers As Boolean)
    Dim PresharedKey As String = "XXXXXXXXXXX"

    Try
        Dim PhoneBook As New RasPhoneBook
        Dim sUsedPhoneBook As String = sPhoneBook
        If bAllUsers Then sUsedPhoneBook = sAllUserPhoneBook

        PhoneBook.Open(sUsedPhoneBook)

        'First remove existing VPN with same name, if exist!
        Try
            PhoneBook.Entries.Remove(VpnName)
        Catch ex As Exception
        End Try

        Dim VpnEntry As RasEntry = RasEntry.CreateVpnEntry(VpnName, Destination, DotRas.RasVpnStrategy.L2tpOnly, DotRas.RasDevice.Create(VpnName, DotRas.RasDeviceType.Vpn))
        VpnEntry.Options.UsePreSharedKey = True
        VpnEntry.Options.IPHeaderCompression = True
        VpnEntry.Options.SoftwareCompression = True
        VpnEntry.Options.NetworkLogOn = True
        VpnEntry.NetworkProtocols.IPv6 = False
        VpnEntry.Options.RequireEap = False
        VpnEntry.Options.RequirePap = True
        VpnEntry.Options.RequireChap = True
        VpnEntry.Options.RequireMSChap2 = True
        VpnEntry.Options.RequireEncryptedPassword = False
        VpnEntry.Options.UseLogOnCredentials = False
        VpnEntry.Options.CacheCredentials = False
        VpnEntry.DnsSuffix = "YYYYYYY.local"
        VpnEntry.Options.UseDnsSuffixForRegistration = True

       ' *********** THE FOLLOWING LINE WILL CRASH ON WINDOWS 10 1803 **********
        PhoneBook.Entries.Add(VpnEntry)
        VpnEntry.UpdateCredentials(RasPreSharedKey.Client, PresharedKey)
        If txt_Username.Text <> "" AndAlso txt_Password.Text <> "" Then
            VpnEntry.UpdateCredentials(New Net.NetworkCredential(txt_Username.Text, txt_Password.Text), False)
            VpnEntry.Options.CacheCredentials = True
            VpnEntry.Update()
        End If

        PhoneBook.Dispose()

        txt_Status.Text = VpnName & " successful added."
        txt_Status.ForeColor = Color.DarkGreen
    Catch ex As Exception
        Console.WriteLine("Error while adding " & VpnName & "." & Environment.NewLine & ex.ToString)
    Finally
    End Try
End Sub

Can somebody help me? I didn't found an updated DotRAS.dll. Best would be a working example without external DLL.

Thank you in advance.

0

There are 0 best solutions below