[AOT] Make BindConverter safe for AOT or mark as unsafe #45578
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
NativeAOT
Pillar: Technical Debt
Status: Resolved
Milestone
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
BindConverter.cs
has a ton ofDynamicallyAccessedMembers.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 ofBuildRenderTree()
must have the same annotations as the version in base classComponentBase.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:
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.BindConverter
to a point where it works without theDynamicallyAccessedMembers.All
annotations, which would require the removal ofTypeDescriptor.GetConverter()
.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
The text was updated successfully, but these errors were encountered: