Repository navigation
Closed
Labels
bugSomething isn't working
Description
HResult=0x80131506
> System.Private.CoreLib.dll!System.Runtime.InteropServices.Marshal.PtrToStructureHelper(System.IntPtr ptr, System.Type structureType) Line 203 C#
System.Private.CoreLib.dll!System.Runtime.InteropServices.Marshal.PtrToStructure(System.IntPtr ptr, System.Type structureType) Line 560 C#
System.Private.CoreLib.dll!System.Runtime.InteropServices.Marshal.PtrToStructure<WinRT.Interop.IUnknownVftbl>(System.IntPtr ptr) Line 580 C#
WinRT.Runtime.dll!WinRT.ObjectReference<WinRT.Interop.IUnknownVftbl>.GetVtables(System.IntPtr thisPtr) Line 210 C#
WinRT.Runtime.dll!WinRT.ObjectReference<WinRT.Interop.IUnknownVftbl>.FromAbi(System.IntPtr thisPtr) Line 200 C#
WinRT.Runtime.dll!WinRT.MarshalInspectable.FromAbi(System.IntPtr ptr) Line 953 C#
WinRT.Runtime.dll!WinRT.MarshalInterface<Windows.Foundation.IAsyncOperation<System.Collections.Generic.IReadOnlyList<Windows.Storage.IStorageItem>>>.FromAbi(System.IntPtr ptr) Line 799 C#
Microsoft.Windows.SDK.NET.dll!ABI.Windows.Foundation.AsyncOperationCompletedHandler<System.Collections.Generic.IReadOnlyList<Windows.Storage.IStorageItem>>.Do_Abi_Invoke.AnonymousMethod__0(System.Delegate invoke) Unknown
WinRT.Runtime.dll!WinRT.ComWrappersSupport.MarshalDelegateInvoke<System.Delegate>(System.IntPtr thisPtr, System.Action<System.Delegate> invoke) Line 62 C#
Microsoft.Windows.SDK.NET.dll!ABI.Windows.Foundation.AsyncOperationCompletedHandler<System.Collections.Generic.IReadOnlyList<Windows.Storage.IStorageItem>>.Do_Abi_Invoke(void* thisPtr, System.IntPtr asyncInfo, Windows.Foundation.AsyncStatus asyncStatus) Unknown
Which happened with this source:
var proxyType = Microsoft.UI.Xaml.VerticalAlignment.Center;
var assembly = proxyType.GetType().GetTypeInfo().Assembly;
foreach (var typeInfo in assembly.**ExportedTypes**)
...System.Private.CoreLib.dll!System.Reflection.RuntimeAssembly.GetExportedTypes() Line 192 C#
System.Private.CoreLib.dll!System.Reflection.Assembly.ExportedTypes.get() Line 72 C#
Microsoft.Toolkit.Uwp.SampleApp.dll!Microsoft.Toolkit.Uwp.SampleApp.Sample.LookForTypeByName(string typeName) Line 660 C#
Microsoft.Toolkit.Uwp.SampleApp.dll!Microsoft.Toolkit.Uwp.SampleApp.Sample.PreparePropertyDescriptorAsync() Line 572 C#
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
jkoritzinsky commentedon May 7, 2020
That stack trace doesn't match up with the provided source. Are you sure you posted the source from the correct thread?
azchohfi commentedon May 7, 2020
I've updated to dotnet core 5.0.100-preview.4.20257.1 and the exception is gone!
azchohfi commentedon May 8, 2020
This code repros it:
This is the stack:
System.ExecutionEngineException
HResult=0x80131506
jkoritzinsky commentedon May 8, 2020
Thanks for the repro! I'll take a look tomorrow!
My guess is we messed up the refcounting somewhere in the custom Async support and are trying to operate on an already-released object. That's usually the cause of this error.
jkoritzinsky commentedon May 8, 2020
Wait, can you give me the outer wrapper of this code as well that calls this through the Windows APIs? Or preferably a zipped up repro of some source I can build locally?
jkoritzinsky commentedon May 8, 2020
The snippet you've given me looks to be entirely .NET-based C# without any of the WinRT apis, so I don't believe I have enough information to put together a good repro to validate that I fix the bug fully.
azchohfi commentedon May 8, 2020
This is not the System.Net.Http.HttpClient, this is the Windows.Web.Http.HttpClient.
System.Net.Http.HttpClient.HttpClient is working fine, and was my work around to this issue.
jkoritzinsky commentedon May 8, 2020
Thanks for clarifying! I'll take a look and fixing this tomorrow.
azchohfi commentedon May 8, 2020
I've also updated to .net core 5 preview 5 (5.0.100-preview.5.20257.3) and I'm also hitting this with the same code as before. Stack on Worker Thread:
Lines of code inside LookForTypeByName method:
Actual thread that throws the exception:
Lines of code of CSWinRT that threw the exception:
There is also this other GC Finalizer Thread:
Running this code:
jkoritzinsky commentedon May 8, 2020
I finally got a repro. As we've both discovered, this only repros under a managed debugger.
What's interesting is that the COM object pointer looks completely valid. It's IUnknown vtable is fully intact and in the right place. Something in the marshalling IL stub is causing it to throw an EngineExecutionException. I'm trying to narrow that down now.
jkoritzinsky commentedon May 12, 2020
.NET 5 runtime builds version 5.0.0-preview.6.20262.3 or later have the fix.
mqudsi commentedon May 25, 2020
Is this the same underlying issue? microsoft/microsoft-ui-xaml#2518 I originally filed it in the WinUI repo, but I'm thinking I should have actually opened a ticket here.
It's an access violation coming on the heels of an
WinRT.IInspectablebad cast, but the violation only happens with the managed debugger attached and reproduces in a clean WinUI project with .NET 5 preview 4 doing WinRT interop. I tried to use the latest .NET preview but WinUI still callsRegisterAsGlobalInstanceinstead ofRegisterForMarshallingso I can't test it out (presumably it's fixed in the WinUI 3 git repo but I haven't gotten around to building it from code).jkoritzinsky commentedon May 25, 2020
Yes that is the same underlying issue. Once we update to use
RegisterForReferenceTracking, the InvalidCastException will go away. The related AV will go away as well, but the actual fix for the underlying issue is in .NET 5.0.0-preview.6.20262.3 or newer.mqudsi commentedon May 28, 2020
Thank you very much for the confirmation, I was very close to losing my mind trying to figure it out and really confused that I seemed to be the only one tripping over it left and right w/ the WinUI 3 preview release.
jkoritzinsky commentedon Jul 1, 2020
Now that .NET 5 Preivew 6 is released, I'm going to close this.