Windows.Networking.Vpn.VpnNativeProfile.get_ConnectionStatus() handle is invalid error

2

I'm working on an application that will automatically create and connect a VPN profile for the user using the Windows VPN API, but get a meaningless error from Windows when trying to inspect its connection status. I'm certain that the profile is created correctly prior to this (I can connect that profile just fine), and that the profile var is non-null and is the profile I've created.

My connection status code looks like:

var vpnManagementAgent = new VpnManagementAgent();
var profiles = await vpnManagementAgent.GetProfilesAsync();
var profile = profiles.SingleOrDefault(p => p.ProfileName == "test");
logger.Trace($"got profile: {profile.PrettyPrint()}");
var result = profile.ConnectionStatus;
logger.Debug($"successfully got profile connection status: {result}");

The attempt to read the ConnectionStatus results in this error:

Error 1/17/2018 12:25:38 PM: IPC: [System.Exception] The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
   at Windows.Networking.Vpn.VpnNativeProfile.get_ConnectionStatus()
   at WindowsFullTrustProcessShared.ProfileService<GetVPNConnectionStatus>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at WindowsFullTrustProcess.MessageListener.<HandleRequest>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at WindowsAppServiceIPC.TypedMessageListenerThread`2.<HandleRequest>d__1.MoveNext()

The function signature in question:

//
// Summary:
//     Gets the current connection status.
//
// Returns:
//     An enumeration value giving current connection status.
public VpnManagementConnectionStatus ConnectionStatus { get; }

And the defintion of the VpnManagementConnectionStatus enum:

//
// Summary:
//     Values used to report the current status of a VPN profile.
[ContractVersion(typeof(UniversalApiContract), 65536)]
public enum VpnManagementConnectionStatus
{
    //
    // Summary:
    //     The profile is disconnected.
    Disconnected = 0,
    //
    // Summary:
    //     The profile is in the process of disconnecting.
    Disconnecting = 1,
    //
    // Summary:
    //     The profile is connected.
    Connected = 2,
    //
    // Summary:
    //     The profile is in the process of connecting.
    Connecting = 3
}

From what I can tell, assuming I have a valid profile object this function should always return a member of this enum. To throw another wrench into the mix, this does actually work fine if the profile exists and is connected prior to running this code. It fails with the above error only if the profile is not connected.

There's obviously more going on in my code to create this profile, I can add those details if someone thinks its relevant. The fact that I can connect such a profile and inspect its status when connected, however, leads me to believe that the problem is not with the profile creation code.

windows
uwp
vpn
asked on Stack Overflow Jan 17, 2018 by tdimmig

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0