WASM issue with ToString
on CustomAttributeData
from System.Reflection
#10660
Labels
area/xBind 🪢
Categorizes an issue or PR as relevant to x:Bind
difficulty/medium 🤔
Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI
kind/bug
Something isn't working
project/binding 🪢
Categorizes an issue or PR as relevant to the binding engine
Current behavior
Have been attempting to read custom assembly metadata attributes in WASM for Toolkit Labs. I think it may be working in the stand-alone Uno project that I built, but need to investigate further.
However, when I was setting up my sample project I had a lot of trouble with
CustomAttributeData
for what was a straight-forward scenario with UWP to bind and dump withToString
.My initial attempt resulted in a compile error:
Couldn't seem to load intermediary file to see what it was complaining about in more detail.
And then a runtime error trying to do the ToString in code-behind:
Runtime Stack Trace from Edge
VM108:1 fail: Uno.UI.Dispatching.CoreDispatcher[0] Dispatcher unhandled exception System.InvalidOperationException: Failed to load UnoTestWASMAssemblyMetadata.MainPage: System.InvalidCastException: Specified cast is not valid. at System.Reflection.CustomAttributeTypedArgument.ToString(Boolean typed) in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Private.CoreLib\src\System\Reflection\CustomAttributeTypedArgument.cs:line 60 at System.Reflection.CustomAttributeTypedArgument.ToString() in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Private.CoreLib\src\System\Reflection\CustomAttributeTypedArgument.cs:line 36 at System.Reflection.CustomAttributeData.ToString() in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Private.CoreLib\src\System\Reflection\CustomAttributeData.cs:line 66 at UnoTestWASMAssemblyMetadata.MainPage.<>c.<.ctor>b__4_0(CustomAttributeData i) in C:\Users\mhawker\source\repos\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata.Shared\MainPage.xaml.cs:line 30 at System.Linq.Enumerable.SelectIListIterator`2[[System.Reflection.CustomAttributeData, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Linq\src\System\Linq\Select.cs:line 280 at System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(IEnumerable`1 collection) in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Private.CoreLib\src\System\Collections\Generic\List.cs:line 85 at System.Linq.Enumerable.ToList[String](IEnumerable`1 source) in D:\a\Uno.DotnetRuntime.WebAssembly\Uno.DotnetRuntime.WebAssembly\runtime\src\libraries\System.Linq\src\System\Linq\ToCollection.cs:line 29 at UnoTestWASMAssemblyMetadata.MainPage..ctor() in C:\Users\mhawker\source\repos\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata.Shared\MainPage.xaml.cs:line 30 at UnoTestWASMAssemblyMetadata.Wasm.MetadataBuilder_644.CreateInstance() in C:\Users\mhawker\source\repos\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata.Wasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.BindableTypeProviders.BindableTypeProvidersSourceGenerator\BindableMetadata.g.cs:line 23434 at Windows.UI.Xaml.Controls.Frame.CreatePageInstance(Type sourcePageType) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 454 at Windows.UI.Xaml.PagePool.DequeuePage(Type pageType) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/PagePool.cs:line 69 at Windows.UI.Xaml.Controls.Frame.CreatePageInstanceCached(Type sourcePageType) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 444 at Windows.UI.Xaml.Controls.Frame.EnsurePageInitialized(PageStackEntry entry) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 435 at Windows.UI.Xaml.Controls.Frame.InnerNavigate(PageStackEntry entry, NavigationMode mode) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 283 at UnoTestWASMAssemblyMetadata.App.OnNavigationFailed(Object sender, NavigationFailedEventArgs e) in C:\Users\mhawker\source\repos\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata.Shared\App.xaml.cs:line 107 at Windows.UI.Xaml.Controls.Frame.InnerNavigate(PageStackEntry entry, NavigationMode mode) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 300 at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter, NavigationTransitionInfo infoOverride) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 276 at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter) in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs:line 271 at UnoTestWASMAssemblyMetadata.App.OnLaunched(LaunchActivatedEventArgs args) in C:\Users\mhawker\source\repos\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata\UnoTestWASMAssemblyMetadata.Shared\App.xaml.cs:line 93 at Windows.UI.Xaml.Application.Initialize() in /home/vsts/work/1/s/src/Uno.UI/UI/Xaml/Application.wasm.cs:line 130 at Uno.UI.Dispatching.CoreDispatcher.InvokeOperationSafe(UIAsyncOperation operation) in /home/vsts/work/1/s/src/Uno.UI.Dispatching/Core/CoreDispatcher.cs:line 337
Think pointing to here: https://github.com/dotnet/runtimelab/blob/04b092003db5ba207d4fa3f3becb7f01828bf16c/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.cs#L60
Expected behavior
Running on UWP:
How to reproduce it (as minimally and precisely as possible)
Attached project zip of all scenarios:
UnoTestWASMAssemblyMetadata.zip
Workaround
Not sure how to get full information contained within the type as easily as was provided with
ToString
, mind you this is a more contrived scenario, as in our case we're getting a specific attribute (though in our other project we don't see that listed, thus why I was building this example).Works on UWP/WinUI
Yes
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
Uno.UI.WebAssembly 4.6.19
Affected platforms
WebAssembly
IDE
Visual Studio 2022
IDE version
17.4.0
Relevant plugins
No response
Anything else we need to know?
Not sure if another edge case of #7893? Though the
ToString
seems to be involved in the later attempts. Maybe it's two slightly different issues underneath?Will go back to Labs and try and compare to see why I'm not seeing the same number of attributes as I did in the sample here at least, so this has given me some insight at least even if it did uncover other issues that I don't think may directly effect us at the moment.
The text was updated successfully, but these errors were encountered: