You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Existing AvaloniaXamlLoader.Load(Uri) and StyleInclude/ResourceInclude in C# code have poor compatibility with AOT, as they require reflection access to find requested resource. These are also marked with RequiresUnreferencedCode for a while now.
When used from XAML, we already optimize StyleInclude/ResourceInclude with direct access instead of reflection. Making this issue less impactful. Yet it still exists #16700 (comment)
Describe the solution you'd like
The more or less .NET friendly solution would be having a method with const string input, intercepted by source generators:
And use source generator to replace this call with a static reference. This article is really useful on that topic.
Interceptors are considered a stable .NET feature since 9.0.200 SDK.
Cons: interceptor solution won't be supported on older SDKs (had to keep reflection fallback there). And they have to enabled explicitly via msbuild property (can be part of our props and enabled by default?).
Describe alternatives you've considered
Keep as is (see workarounds)
Wait until Interop Type Mapping is formalized. Would it help? Can we create a custom "type universe" for XAML compiler types?
Additional context
Since XAML compiler already optimizes StyleInclude/ResourceInclude usage, it provides several possible workarounds:
If you own the included XAML resource, you can use x:Class on it, with a blank C# class created. This way you can reference this resource by its C# type instead of StyleInclude/ResourceInclude. Making it completely compiler safe.
If you don't that resource, you still can create another XAML file with x:Class that has the include.
More your StyleInclude/ResourceIncludeto XAML only. If you don't need to include them right away, you can still define them in XAML for later use. This MyStyleInclude can be read and included manually from C# code when needed:
Is your feature request related to a problem? Please describe.
Existing
AvaloniaXamlLoader.Load(Uri)
andStyleInclude/ResourceInclude
in C# code have poor compatibility with AOT, as they require reflection access to find requested resource. These are also marked withRequiresUnreferencedCode
for a while now.When used from XAML, we already optimize
StyleInclude/ResourceInclude
with direct access instead of reflection. Making this issue less impactful. Yet it still exists #16700 (comment)Describe the solution you'd like
The more or less .NET friendly solution would be having a method with const string input, intercepted by source generators:
And use source generator to replace this call with a static reference. This article is really useful on that topic.
Interceptors are considered a stable .NET feature since 9.0.200 SDK.
Cons: interceptor solution won't be supported on older SDKs (had to keep reflection fallback there). And they have to enabled explicitly via msbuild property (can be part of our props and enabled by default?).
Describe alternatives you've considered
Additional context
Since XAML compiler already optimizes
StyleInclude/ResourceInclude
usage, it provides several possible workarounds:x:Class
on it, with a blank C# class created. This way you can reference this resource by its C# type instead of StyleInclude/ResourceInclude. Making it completely compiler safe.StyleInclude/ResourceInclude
to XAML only. If you don't need to include them right away, you can still define them in XAML for later use. ThisMyStyleInclude
can be read and included manually from C# code when needed:The text was updated successfully, but these errors were encountered: