Skip to content

Commit d4a032e

Browse files
committed
Fix issue where psedit cannot open empty files in remote sessions
Resolves PowerShell/vscode-powershell#842
1 parent 5700921 commit d4a032e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: src/PowerShellEditorServices/Session/RemoteFileManager.cs

+15-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,21 @@ private void HandlePSEventReceived(object sender, PSEventArgs args)
418418
}
419419
else
420420
{
421-
byte[] fileContent =
422-
args.SourceArgs.Length == 2
423-
? (byte[])((args.SourceArgs[1] as PSObject).BaseObject)
424-
: new byte[0];
421+
byte[] fileContent = null;
422+
423+
if (args.SourceArgs.Length == 2)
424+
{
425+
PSObject sourceObj = args.SourceArgs[1] as PSObject;
426+
if (sourceObj != null)
427+
{
428+
fileContent = sourceObj.BaseObject as byte[];
429+
}
430+
}
431+
432+
// If fileContent is still null after trying to
433+
// unpack the contents, just return an empty byte
434+
// array.
435+
fileContent = fileContent ?? new byte[0];
425436

426437
localFilePath =
427438
this.StoreRemoteFile(

0 commit comments

Comments
 (0)