Skip to content

OutOfProcCOM not working with clients in PowerShell or using C# dynamic #22364

Open
@Molinarius

Description

@Molinarius

Issue description

With clients in PowerShell or using C# dynamic, I cannot get the OutOfProcCOM example to work; I additionally tried it with Pyhton, too, and it didn't work, but I'm not too firm with Pyhton.

C# .NET5 dynamic:

> Environment.Version
[5.0.2]
> var type = Type.GetTypeFromCLSID(Guid.Parse("AF080472-F173-4D9D-8BE7-435776617347"));
> dynamic c = Activator.CreateInstance(type);
> c.ComputePi()
System.NotSupportedException: Specified method is not supported.
  + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(int)
  + Microsoft.CSharp.RuntimeBinder.ComInterop.ComRuntimeHelpers.GetITypeInfoFromIDispatch(Microsoft.CSharp.RuntimeBinder.ComInterop.IDispatch)
  + Microsoft.CSharp.RuntimeBinder.ComInterop.IDispatchComObject.EnsureScanDefinedMethods()
  + Microsoft.CSharp.RuntimeBinder.ComInterop.IDispatchComObject.System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression)
  + System.Dynamic.DynamicMetaObject.Create(object, System.Linq.Expressions.Expression)
  + System.Dynamic.DynamicMetaObjectBinder.Bind(object[], ReadOnlyCollection<System.Linq.Expressions.ParameterExpression>, System.Linq.Expressions.LabelTarget)
  + System.Runtime.CompilerServices.CallSiteBinder.BindCore<T>(CallSite<T>, object[])
  + System.Dynamic.UpdateDelegates.UpdateAndExecute1<T0, TRet>(System.Runtime.CompilerServices.CallSite, T0)
  + System.Dynamic.UpdateDelegates.UpdateAndExecute1<T0, TRet>(System.Runtime.CompilerServices.CallSite, T0)

Exactly the same exception was thrown after I added dynamic dyn = obj; dyn.ComputePi(); in the ManagedClient project of the example.

C# .NET Framework 4 dynamic:

> Environment.Version
[4.0.30319.42000]
> var type = Type.GetTypeFromCLSID(Guid.Parse("AF080472-F173-4D9D-8BE7-435776617347"));
> dynamic c = Activator.CreateInstance(type);
> c.ComputePi()
System.NotSupportedException: Specified method is not supported.
  + System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(int, System.IntPtr)
  + System.Dynamic.ComRuntimeHelpers.GetITypeInfoFromIDispatch(System.Dynamic.IDispatch, bool)
  + System.Dynamic.IDispatchComObject.EnsureScanDefinedMethods()
  + System.Dynamic.IDispatchComObject.System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression)
  + System.Dynamic.DynamicMetaObject.Create(object, System.Linq.Expressions.Expression)
  + System.Dynamic.DynamicMetaObjectBinder.Bind(object[], ReadOnlyCollection<System.Linq.Expressions.ParameterExpression>, System.Linq.Expressions.LabelTarget)
  + System.Runtime.CompilerServices.CallSiteBinder.BindCore<T>(CallSite<T>, object[])
  + System.Dynamic.UpdateDelegates.UpdateAndExecute1<T0, TRet>(System.Runtime.CompilerServices.CallSite, T0)
  + System.Dynamic.UpdateDelegates.UpdateAndExecute1<T0, TRet>(System.Runtime.CompilerServices.CallSite, T0)

PowerShell 5:

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.1490
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1490
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> $type = [Type]::GetTypeFromCLSID("AF080472-F173-4D9D-8BE7-435776617347")
> $c = [Activator]::CreateInstance($type)
> $c.ComputePi()
Specified method is not supported.
At line:1 char:1
+ $c.ComputePi()
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException

PowerShell 7.1.0:

> $PSVersionTable

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

> $type = [Type]::GetTypeFromCLSID("AF080472-F173-4D9D-8BE7-435776617347")
> $c = [Activator]::CreateInstance($type)
> $c.ComputePi()
OperationStopped: Specified method is not supported.

I tried adding support for IDispatch to the OutOfProcCOM example, and changed the target to .NET 5, but the behavior remained unchanged. I guess I didn't add that IDispatch support correctly because I don't have the necessary knowledge.

By the way, an out-of-process COM server I created with .NET Framework 4.7 (what required some workarounds) works with PowerShell and C# dynamic clients and all other clients I know.

Target framework

  • .NET Core 3.1, 5
  • .NET Framework
  • .NET Standard
dotnet --info output or About VS info
.NET SDK (reflecting any global.json):
 Version:   5.0.102
 Commit:    71365b4d42

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support):
  Version: 5.0.2
  Commit:  cb5f173b96

.NET SDKs installed:
  5.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]```
</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting-on-feedbackWaiting for feedback from SMEs before they can be merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions