-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ComponentModel IntrinsicTypeConverters are not linker safe #38582
Comments
Tagging subscribers to this area: @safern |
I've been thinking about these kinds of patterns in the past. I think the safest way to approach this is through a wrapper class. Something like: struct ReflectableHashtable
{
private Hashtable _table;
public void Add(Type x, [DynamicallyAccessed(X)] Type y) => _table.Add(x, y);
[UnconditionalSuppressMessage(blah)]
[DynamicallyAccessed(X)]
public this[Type k] => _table[k];
} Linker cannot fully see through this, so it needs a suppression, but it's a small struct and it's easy to audit that it is in fact safe. |
That's a good idea, I'll see if I can get that to work. In mono, it looks like it was annotated using Which can easily get out of sync. One other option I was playing around with was to use a |
Calling
TypeDescriptor.GetConverter(typeof(Guid))
, or passing other low-level system types, in a trimmed app can cause failures because we are using reflection to create the object.Underneath, we have a map of
Type
=>Converter Type
:runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs
Lines 103 to 136 in 4f9ae42
And then we use that
Converter Type
and create an instance of it using reflection:runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.ReflectedTypeData.cs
Lines 220 to 222 in 4f9ae42
runtime/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs
Lines 1322 to 1336 in 4f9ae42
However, the linker cannot tell that it is supposed to preserve the constructor on these converters because it can't see through adding types to a collection.
Blazor is currently working around this issue here: https://github.com/dotnet/aspnetcore/blob/e906c2067be5552bf15f0bd2a9c793a6ad4d3dc6/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/LinkerWorkaround.xml#L11-L13
See related dotnet/aspnetcore#23262
The text was updated successfully, but these errors were encountered: