TypeLoadException is thrown when calling 'GetEnumerator()' on a COM object that has been successfully casted to 'IEnumerable' #21690
Comments
@daxian-dbw Thanks for reporting this issue. As previously discussed, CoreCLR doesn't support IDispatch (and that's why you are implementing your own IDispatch). IEnumerable.GetEnumerator uses IDispatch.Invoke(DISPID_NEWENUM) under the hood (that's the convention for IDispatch objects to support enumeration). You need to write your own enumeration code to support that pattern in CoreCLR. Based on what you already have (IDispatch and VARIANT support), it should be pretty straight-forward. I'll be happy to help out offline if you need any help. |
I have a PR out to make the exception better: dotnet/coreclr#11865 |
@yizhang82 thanks for the taking a look. We have been using the pattern
|
The casting will keep working (mainly I want to avoid confusion because IEnumerable casting has too many possible scenarios) but IEnumerable.GetEnumerator will throw. |
After PR dotnet/coreclr#11865, exception error message is now:
|
@yizhang82 the PR is only in master, hence in 2.1. Please either reopen this issue to track porting into rel/2.0.0 branch, or change milestone of this issue appropriately to 2.1. Thanks! |
This is a simple fix for better exception and not needed in 2.0. Moved to |
@yizhang82 I downloaded .NET Core 2.1 RC and i have the mentioned exception.
I don't understand if exists a workaround to fix this issue. |
This is happening with
netcoreapp2.0
version2.0.0-preview1-002106-00
, on windows 10 desktop.UPDATE (2/6/2020)
With .NET Core 3.1,
(comObject as IEnumerable)?.GetEnumerator()
works now.However, casting a
comObject
toIEnumerator
still doesn't work, for the following code will fail:Summary
I get the ShellWindows object by calling
Shell.Application.Windows()
method with C#. TheShellWindows
object is enumerable, and it can be successfully cast toIEnumerable
. After that, when I callGetEnumerator()
on the casted IEnumerable object, a TypeLoadException is thrown:Will the type
System.Runtime.InteropServices.ComTypes.IEnumerable
be added to .NET Core 2.0?Repro
Expected Result
GetEnumerator()
is successful, and thenMoveNext()
works too.Actual Result
Environment
The text was updated successfully, but these errors were encountered: