I have a PS Cmdlet in C# - its ProcessRecord function looks like this:

var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyClient = new KeyVaultClient(
    new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

var cert = await keyClient.GetCertificateAsync(keyVaultCertUri);

My problem is when I call any KeyVaultClient API from within my Cmdlet, VS simply ends the debugging session. There's no useful output in the Debug window; no exception is thrown; nada. The debugging session just suddenly ends.

How can I debug what's going on so I can make this call successfully?

1 Answers

0
Phani On Best Solutions

The issue is that, when inheriting from Cmdlet, ProcessRecord can’t be async. If you perform an await directly within ProcessRecord, it will immediately end processing. Thus, any async calls must be made synchronous in ProcessRecord for execution to function.

In terms of debugging, I found no evidence in VS that await was the problem. A colleague found an open issue on the PowerShell Git page describing this problem behavior.