-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
In trying to use Microsoft.Extensions.Caching.StackExchangeRedis in a Native AOT app (see dotnet/aspnetcore#45910), I'm getting the following warnings from this code:
StackExchange.Redis/src/StackExchange.Redis/Configuration/DefaultOptionsProvider.cs
Lines 208 to 242 in b1fddf3
| internal static string? TryGetAzureRoleInstanceIdNoThrow() | |
| { | |
| string? roleInstanceId; | |
| try | |
| { | |
| Assembly? asm = null; | |
| foreach (var asmb in AppDomain.CurrentDomain.GetAssemblies()) | |
| { | |
| if (asmb.GetName()?.Name?.Equals("Microsoft.WindowsAzure.ServiceRuntime") == true) | |
| { | |
| asm = asmb; | |
| break; | |
| } | |
| } | |
| if (asm == null) | |
| return null; | |
| var type = asm.GetType("Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment"); | |
| // https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.isavailable.aspx | |
| if (type?.GetProperty("IsAvailable") is not PropertyInfo isAvailableProp | |
| || isAvailableProp.GetValue(null, null) is not bool isAvailableVal | |
| || !isAvailableVal) | |
| { | |
| return null; | |
| } | |
| var currentRoleInstanceProp = type.GetProperty("CurrentRoleInstance"); | |
| var currentRoleInstanceId = currentRoleInstanceProp?.GetValue(null, null); | |
| roleInstanceId = currentRoleInstanceId?.GetType().GetProperty("Id")?.GetValue(currentRoleInstanceId, null)?.ToString(); | |
| if (roleInstanceId.IsNullOrEmpty()) | |
| { | |
| roleInstanceId = null; | |
| } |
/_/src/StackExchange.Redis/Configuration/DefaultOptionsProvider.cs(225): Trim analysis warning IL2026: StackExchange.Redis.Configuration.DefaultOptionsProvider.TryGetAzureRoleInstanceIdNoThrow(): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. [C:\git\azure-activedirectory-identitymodel-extensions-for-dotnet\test\Microsoft.IdentityModel.AotCompatibility.TestApp\Microsoft.IdentityModel.AotCompatibility.TestApp.csproj]
/_/src/StackExchange.Redis/Configuration/DefaultOptionsProvider.cs(228): Trim analysis warning IL2075: StackExchange.Redis.Configuration.DefaultOptionsProvider.TryGetAzureRoleInstanceIdNoThrow(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Reflection.Assembly.GetType(String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\git\azure-activedirectory-identitymodel-extensions-for-dotnet\test\Microsoft.IdentityModel.AotCompatibility.TestApp\Microsoft.IdentityModel.AotCompatibility.TestApp.csproj]
/_/src/StackExchange.Redis/Configuration/DefaultOptionsProvider.cs(235): Trim analysis warning IL2075: StackExchange.Redis.Configuration.DefaultOptionsProvider.TryGetAzureRoleInstanceIdNoThrow(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Reflection.Assembly.GetType(String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\git\azure-activedirectory-identitymodel-extensions-for-dotnet\test\Microsoft.IdentityModel.AotCompatibility.TestApp\Microsoft.IdentityModel.AotCompatibility.TestApp.csproj]
/_/src/StackExchange.Redis/Configuration/DefaultOptionsProvider.cs(237): Trim analysis warning IL2075: StackExchange.Redis.Configuration.DefaultOptionsProvider.TryGetAzureRoleInstanceIdNoThrow(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\git\azure-activedirectory-identitymodel-extensions-for-dotnet\test\Microsoft.IdentityModel.AotCompatibility.TestApp\Microsoft.IdentityModel.AotCompatibility.TestApp.csproj]
I'm not sure exactly what this code is for. If it isn't necessary from a trimmed/AOT app, maybe the warnings could just be suppressed? Either way, it would be good to address these warnings so devs using Redis caching in Native AOT apps don't get the warnings.
cc @mgravell
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels