为什么 UWP 函数 Add Profile FromObject Async() 抛出异常?

Why UWP function AddProfileFromObjectAsync() throws exeption?

我正在尝试使用 UWP 创建 VPN 连接,但是当它 运行 时,我从 AddProfileFromObjectAsync() exception message.

中收到异常
auto  mgr = ref new VpnManagementAgent();
auto  profile = ref new VpnNativeProfile();

profile->AlwaysOn               = false;
profile->NativeProtocolType     = VpnNativeProtocolType::L2tp;
profile->ProfileName            = "TestVpn";
profile->RememberCredentials    = true;
profile->RequireVpnClientAppUI  = true;
profile->RoutingPolicyType      = VpnRoutingPolicyType::ForceAllTrafficOverVpn;
profile->TunnelAuthenticationMethod = VpnAuthenticationMethod::PresharedKey;
profile->UserAuthenticationMethod   = VpnAuthenticationMethod::Mschapv2;
profile->Servers->Append("45.87.213.134");

auto profileStatus = mgr->AddProfileFromObjectAsync(profile);

从这个document,它提到如果你想使用VpnManagementAgent class,你需要添加networkingVpnProvider能力。 networkingVpnProvider 功能允许应用程序完全访问 VPN 功能,包括管理连接和提供 VPN 插件功能的能力。您可以像下面这样添加:

.appxmanifest:

<Package ...... 
     xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
     IgnorableNamespaces="uap mp rescap">

     ......

<rescap:Capability Name="networkingVpnProvider" />