-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
.NET 9, ILC reports trimmer warnings for k__BackingField
for auto-properties
#108978
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
The warning is due to Here's an example of what the warning guards against: using System.Reflection;
using System.Diagnostics.CodeAnalysis;
var t = new C().GetType();
AssignField(t, typeof(D));
if (C.P.GetMethods().Length == 0) {
throw new Exception("No methods"); // Will throw in AOT only
}
static void AssignField([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicFields)] Type t, Type value) {
foreach (var field in t.GetFields(BindingFlags.NonPublic | BindingFlags.Static)) {
field.SetValue(null, value);
}
}
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicFields)]
class C {
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public static Type? P { get; set; }
}
class D {
public static void M() {}
} Changing it to an explicitly implemented property won't help, it'll just move the warning to the explicit field. A more precise analysis could potentially get rid of these warnings and instead warn at the |
So, I think the issue here is that the warning message could be improved. If the property was mentioned instead of |
k__BackingField
for auto-properties
Description
For the property:
We got the trimmer warning:
This was inside a .NET MAUI project on iOS.
We think something like this will workaround this case, but CI is ongoing:
Reproduction Steps
dotnet new maui
Root everything:
dotnet publish -c Release -p:PublishAot=true -f net9.0-ios
Expected behavior
We would not get trimmer warnings for
k__BackingField
.Actual behavior
We get trimmer warnings for
k__BackingField
.Regression?
Not sure
Known Workarounds
I assume we can do:
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: