in src/Public/Commands/PushOutputBindingCommand.cs [159:191]
private ReadOnlyBindingInfo GetBindingInfo(string name)
{
Guid currentRunspaceId = Runspace.DefaultRunspace.InstanceId;
var bindingMap = FunctionMetadata.GetOutputBindingInfo(currentRunspaceId);
// If the instance id doesn't get us back a binding map, then we are not running in one of the PS worker's Runspace(s).
// This could happen when a custom Runspace is created in the function script, and 'Push-OutputBinding' is called in that Runspace.
if (bindingMap == null)
{
string errorMsg = PowerShellWorkerStrings.DontPushOutputOutsideWorkerRunspace;
ErrorRecord er = new ErrorRecord(
new InvalidOperationException(errorMsg),
nameof(PowerShellWorkerStrings.DontPushOutputOutsideWorkerRunspace),
ErrorCategory.InvalidOperation,
targetObject: currentRunspaceId);
this.ThrowTerminatingError(er);
}
if (!bindingMap.TryGetValue(name, out ReadOnlyBindingInfo bindingInfo))
{
string errorMsg = string.Format(PowerShellWorkerStrings.BindingNameNotExist, name);
ErrorRecord er = new ErrorRecord(
new InvalidOperationException(errorMsg),
nameof(PowerShellWorkerStrings.BindingNameNotExist),
ErrorCategory.InvalidOperation,
targetObject: name);
this.ThrowTerminatingError(er);
}
return bindingInfo;
}