'Create ikev2 profile using dotRas

I've trying to create ikev2 with special options using doRas1.3 with no success giving error

'entry' contains invalid or conflicting settings. Please verify the settings are correct and try again.
Parameter name: entry

My simple code

string vpnName = "MyVPN";
        string destination = "SERVER_ADDRESS";
        string username = "test";
        string password = "test123";

    try
    {
        RasPhoneBook phoneBook = new RasPhoneBook();
        string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);

        phoneBook.Open(path);
        RasEntry vpnEntry = RasEntry.CreateVpnEntry(vpnName, destination,
            RasVpnStrategy.IkeV2Only, 
            RasDevice.Create(vpnName, RasDeviceType.Vpn), 
            false);
      
        //vpnEntry.Options.UsePreSharedKey = false;
        vpnEntry.Options.UseLogOnCredentials = false  ;
        vpnEntry.Options.RequireMSChap2 = true;
        vpnEntry.Options.RequireEap = true;
        //vpnEntry.Options.RequireDataEncryption = true;
        //vpnEntry.Options.RequirePap = false  ;
        //  vpnEntry.Options.RequireMSEncryptedPassword = true;
        vpnEntry.Options.CacheCredentials = false;

        phoneBook.Entries.Add(vpnEntry);

        //update user credintials
        NetworkCredential myCred = new NetworkCredential(username, password, destination);
        vpnEntry.UpdateCredentials(myCred, true);
        bool isUpdated = vpnEntry.Update();

        Console.WriteLine(@"Entry Changed ");

    }
    catch (Exception ex)
    {
        Console.WriteLine(@"ERROR: " + ex.Message + " Details: " + ex.Source);

    }

I have created ikev2 profile using PowerShell using this commands and its working very fine

Add-VpnConnection -Name "IKEv2" `
    -ServerAddress "111.222.184.117" `
    -TunnelType "IKEv2" `
    -AuthenticationMethod "EAP" `
    -EncryptionLevel "Maximum" `
    -RememberCredential `
    
    
Set-VpnConnectionIPsecConfiguration -Name "IKEv2" `
    -AuthenticationTransformConstants GCMAES256 `
    -CipherTransformConstants GCMAES256 `
    -DHGroup ECP384 `
    -IntegrityCheckMethod SHA384 `
    -PfsGroup ECP384 `
    -EncryptionMethod GCMAES256

How to create ikev2 profile using dotRas as same as powershell profile settings?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source