Open michael-hawker opened 1 year ago
This looks like there are two separate issues here.
First, it seems that adding a function invocation to the pathless cast is not working well, but even when doing this:
<TextBlock DataContext="{x:Bind (ref:CustomAttributeData))"
Text="{Binding}" />
I'm getting:
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.AssignmentExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax'
I'm not able to repro in Unit Tests, so there must be something else that breaks that particular scenario.
That being said, you're not forced to use x:Bind here, and a simple:
<TextBlock Text="{Binding}" />
Will be enough as a workaround.
Thanks @jeromelaban, I didn't try just using {Binding}
but with the original object type. That does output the ToString
result properly! 🎉 It is weird that calling the ToString
method directly in code-behind causes an exception though? I don't know how it'd take a different path.
Still investigating in Labs what might be going on there with our attributes, but our generation of them is a bit different. This info will help that investigation though. Thanks!
Great! As for the error with CustomAttribute, I suspect this is a runtime issue that may (or may not) be fixed with .NET 7 (bootstrapper 7.0.x). Could be worth a try.
Ah, figured out my base issue we had in Labs in regard to where I was retrieving the Metadata (which existed and was valid with our new generation system), but not where I was setting the property/evaluating the bindings... I was basically hitting the #2666 #2872 issues again.
So at least I've got everything I need working for Labs at the moment!
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
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.