Skip to content

System.Runtime.Interopservices.Marshal::GetActiveObject doesn't exist in PowerShell 7+ #5081

@FKramerJr

Description

@FKramerJr

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When running [Visual Studio Code PS script there is an error when running System.Runtime.Interopservices.Marshal::GetActiveObject('Excel.Application'. This same code works in PS or PS ISE

PowerShell Version

$PSVersionTable; $Host

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.5.0
InstanceId       : aa2c81c1-9b98-41c1-b330-e63a5d54db90
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.95.1
65edc4939843c90c34d61f4ce11704f09d3e5cb6
x64

Extension Version

ms-vscode.powershell@2024.5.0

Steps to Reproduce

$Excel = new-object -comobject Excel.Application
$Excel.workbooks.Add()
$Excel.Visible = $true
$Wb = $Excel.ActiveWorkbook
$Ws = $Excel.ActiveSheet

InvalidOperation: Method invocation failed because System.Runtime.InteropServices.Marshal does not contain a method named 'GetActiveObject'.

Visuals

VSC Error

Logs

PowerShellEditorServices-22300.log
StartEditorServices-22300.log
vscode-powershell.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: PowerShell CoreBugs when using PowerShell Core.IgnoreExclude from the changelog.Issue-BugA bug to squash.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions