Skip to content

Create COM objects on PowerShell gives an error Constructor on type 'System.__ComObject' not found. #57107

@adityapatwardhan

Description

@adityapatwardhan

Description

On a PowerShell build with .NET 6 Preview 7, when a new instance of a COM object is done, we get an error: Constructor on type 'System.__ComObject' not found. which is System.MissingMethodException

Gist for sample code to repro the error:

https://gist.github.com/adityapatwardhan/954af5c2d894d889e1465c614ecf7e1a

Configuration

.NET 6 Preview 7 SDK on Windows 10 x64.

Regression?

Yes, from .NET 6 Preview 6

Other information

Repro for the issue is on PowerShell built against .NET 6 Preview 7 SDK.

PS C:> $fileSystem = New-Object -ComObject scripting.filesystemobject
New-Object: Constructor on type 'System.__ComObject' not found.
PS C:> Get-Error

Exception :
Type : System.MissingMethodException
Message : Constructor on type 'System.__ComObject' not found.
TargetSite :
Name : CreateInstanceImpl
DeclaringType : System.RuntimeType, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2146233069
StackTrace :
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) in System.Private.CoreLib.dll:token 0x60006c6+0x173
at System.Activator.CreateInstance(Type type, Object[] args) in System.Private.CoreLib.dll:token 0x60009e0+0x0
at Microsoft.PowerShell.Commands.NewObjectCommand.SafeCreateInstance(Type t, Object[] args) in D:\PSGit\PowerShell\src\Microsoft.PowerShell.Commands.Utility\commands\utility\New-Object.cs:line 359
CategoryInfo : InvalidOperation: (:) [New-Object], MissingMethodException
FullyQualifiedErrorId : NoPublicCtorMatch,Microsoft.PowerShell.Commands.NewObjectCommand

InvocationInfo :
MyCommand : New-Object
ScriptLineNumber : 1
OffsetInLine : 15
HistoryId : 9
Line : $fileSystem = New-Object -ComObject scripting.filesystemobject
PositionMessage : At line:1 char:15
+ $fileSystem = New-Object -ComObject scripting.filesystemobject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : New-Object
CommandOrigin : Internal
ScriptStackTrace : at , : line 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions