Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
BindConverter.cs
has a ton of DynamicallyAccessedMembers.All
annotations. It seems the class barely made the cut for trim safety, but definitely will not work in its current state for AOT.
Why not just mark those methods as requiring dynamic code and therefore unsafe for AOT?
Unfortunately, our forms input classes implement BindConverter.TryConvertTo<TValue>()
, and to mark those as unsafe puts us in a jam since their implementation of BuildRenderTree()
must have the same annotations as the version in base class ComponentBase.cs
. Clearly, we can't take dynamic code annotations up the call chain unless we want large parts of Blazor to be marked as unsafe for AOT.
Why does BindConverter need so many DynamicallyAccessedMembers annotations?
The use of TypeDescriptor.GetConverter()
(see here and here) seem to be the culprit and to my knowledge there will be no effort to remove any dynamic code annotations from there.
Describe the solution you'd like
I see a few different options here:
- Go ahead and mark everything
BindConverter
touches (and the subsequent warnings that bubble up the call chain) as unsafe for AOT. This would create an obstacle to Blazor being a useful framework for Native AOT solutions. - Get
BindConverter
to a point where it works without theDynamicallyAccessedMembers.All
annotations, which would require the removal ofTypeDescriptor.GetConverter()
. - Mark
BindConverter
as unsafe and create safe paths for classes that useBindConverter
but also want to enable AOT by using an if-else block that checks forRuntimeFeature.IsDynamicCodeCompiled
.
Additional context
CC @JamesNK @eerhardt for any advice, additional context, or cautionary tales surrounding this.
Part of effort tracked in #45473