microsoft-authentication-library-for-dotnet: [Bug] Microsoft.Identity.Client doesn't support IL Trimming
.NET6 added IL Trimming (https://devblogs.microsoft.com/dotnet/announcing-net-6/#il-trimming) Unfortunately, MSAL.Net doesn’t support it.
Which version of MSAL.NET are you using? Microsoft.Identity.Client 4.44.0
Platform .NET 6
What authentication flow has the issue?
- Desktop / Mobile
- Interactive
- Integrated Windows Authentication
- Username Password
- Device code flow (browserless)
- Web app
- Authorization code
- On-Behalf-Of
- Daemon app
- Service to Service calls
Is this a new or existing app? This is a new app or experiment.
Repro
A very simple .NET 6 app:
string[] scopes = new string[] { "user.read" };
var clientId = "...";
var app = PublicClientApplicationBuilder
.Create(clientId)
.WithRedirectUri("http://localhost")
.Build();
var accounts = await app.GetAccountsAsync();
try
{
result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync();
}
catch (MsalUiRequiredException)
{
result = await app.AcquireTokenInteractive(scopes)
.ExecuteAsync();
}
With:
<PublishTrimmed>true</PublishTrimmed>
<PublishSingleFile>true</PublishSingleFile>
And built with:
dotnet publish --self-contained -r win-x64 /p:Configuration=Release /p:TrimmerSingleWarn=false
Will produce dozens of warnings/errors, such as:
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.<>c.<GetExtensionDataMemberForType>b__43_0(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter 'baseType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.<>c.<GetExtensionDataMemberForType>b__43_0(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.<>c.<GetExtensionDataMemberForType>b__43_0(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'baseType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.<>c.<GetExtensionDataMemberForType>b__43_0(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Converters.BinaryConverter.EnsureReflectionObject(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructor(Type[])'. The parameter 't' of method 'Microsoft.Identity.Json.Converters.BinaryConverter.EnsureReflectionObject(Type)' 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.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.DynamicUtils.BinderWrapper.CreateMemberCalls(): Using member 'Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags,String,Type,IEnumerable<CSharpArgumentInfo>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using dynamic types might cause types or members to be removed by trimmer.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.DynamicUtils.BinderWrapper.CreateMemberCalls(): Using member 'Microsoft.CSharp.RuntimeBinder.Binder.SetMember(CSharpBinderFlags,String,Type,IEnumerable<CSharpArgumentInfo>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using dynamic types might cause types or members to be removed by trimmer.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.CollectionUtils.ResolveEnumerableCollectionConstructor(Type,Type,Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors(BindingFlags)'. The parameter 'collectionType' of method 'Microsoft.Identity.Json.Utilities.CollectionUtils.ResolveEnumerableCollectionConstructor(Type,Type,Type)' 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.
ILLink : Trim analysis error IL2057: Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String,Boolean)'. It's not possible to guarantee the availability of the target type.
ILLink : Trim analysis error IL2072: Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. 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.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&): Using member 'System.ComponentModel.TypeDescriptor.GetConverter(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.
ILLink : Trim analysis error IL2067: Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&)' 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.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ConvertUtils.TryConvertInternal(Object,CultureInfo,Type,Object&): Using member 'System.ComponentModel.TypeDescriptor.GetConverter(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.
ILLink : Trim analysis error IL2067: Microsoft.Identity.Json.Converters.DataSetConverter.ReadJson(JsonReader,Type,Object,JsonSerializer): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Converters.DataSetConverter.ReadJson(JsonReader,Type,Object,JsonSerializer)' 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.
ILLink : Trim analysis error IL2072: Microsoft.Identity.Json.Converters.DataTableConverter.CreateRow(JsonReader,DataTable,JsonSerializer): 'dataType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Data.DataColumn.DataColumn(String,Type)'. The return value of method 'Microsoft.Identity.Json.Converters.DataTableConverter.GetColumnDataType(JsonReader)' 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.
ILLink : Trim analysis error IL2067: Microsoft.Identity.Json.Converters.DataTableConverter.ReadJson(JsonReader,Type,Object,JsonSerializer): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Converters.DataTableConverter.ReadJson(JsonReader,Type,Object,JsonSerializer)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetAttributeConstructor(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Type.GetConstructors(BindingFlags)'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetAttributeConstructor(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetAttributeConstructor(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructor(Type[])'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetAttributeConstructor(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetImmutableConstructor(Type,JsonPropertyCollection): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors()'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetImmutableConstructor(Type,JsonPropertyCollection)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetParameterizedConstructor(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors(BindingFlags)'. The parameter 'objectType' of method 'Microsoft.Identity.Json.Serialization.DefaultContractResolver.GetParameterizedConstructor(Type)' 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.
ILLink : Trim analysis error IL2065: Microsoft.Identity.Json.Serialization.DefaultContractResolver.SetExtensionDataDelegates(JsonObjectContract,MemberInfo): Value passed to implicit 'this' parameter of method 'System.Type.GetProperty(String,BindingFlags,Binder,Type,Type[],ParameterModifier[])' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Serialization.DefaultSerializationBinder.GetGenericTypeFromTypeName(String,Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2055: Microsoft.Identity.Json.Serialization.DefaultSerializationBinder.GetGenericTypeFromTypeName(String,Assembly): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey<String,String>): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2057: Microsoft.Identity.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(StructMultiKey<String,String>): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.DynamicReflectionDelegateFactory.GenerateCreateDefaultConstructorIL(Type,ILGenerator,Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Type.GetConstructor(BindingFlags,Binder,Type[],ParameterModifier[])'. The parameter 'type' of method 'Microsoft.Identity.Json.Utilities.DynamicReflectionDelegateFactory.GenerateCreateDefaultConstructorIL(Type,ILGenerator,Type)' 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.
ILLink : Trim analysis error IL2057: Microsoft.Identity.Json.Converters.EntityKeyMemberConverter.ReadJson(JsonReader,Type,Object,JsonSerializer): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
ILLink : Trim analysis error IL2055: Microsoft.Identity.Json.Utilities.FSharpUtils.BuildMapCreator<TKey,TValue>(): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
ILLink : Trim analysis error IL2060: Microsoft.Identity.Json.Utilities.FSharpUtils.CreateSeq(Type): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.FSharpUtils.EnsureInitialized(Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.FSharpUtils.EnsureInitialized(Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.FSharpUtils.EnsureInitialized(Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.FSharpUtils.EnsureInitialized(Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.FSharpUtils.EnsureInitialized(Assembly): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(Type,Type,Type&,ObjectConstructor`1&): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(Type,Type,Type&,ObjectConstructor`1&): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2055: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(Type,Type,Type&,ObjectConstructor`1&): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
ILLink : Trim analysis error IL2060: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(Type,Type,Type&,ObjectConstructor`1&): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract(Type,Type,Type,Type&,ObjectConstructor`1&): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract(Type,Type,Type,Type&,ObjectConstructor`1&): Using member 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
ILLink : Trim analysis error IL2055: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract(Type,Type,Type,Type&,ObjectConstructor`1&): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
ILLink : Trim analysis error IL2060: Microsoft.Identity.Json.Utilities.ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract(Type,Type,Type,Type&,ObjectConstructor`1&): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Linq.JContainer.System.ComponentModel.ITypedList.GetItemProperties(PropertyDescriptor[]): Using member 'System.ComponentModel.ICustomTypeDescriptor.GetProperties()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. PropertyDescriptor's PropertyType cannot be statically discovered.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetConverter(): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetConverter()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetConverter()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent(): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty(): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetEditor(Type): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetEditor(Type)' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetEditor(Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetEvents(Attribute[]): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetEvents(Attribute[])' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetEvents(Attribute[])' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetProperties(): Using member 'System.ComponentModel.ICustomTypeDescriptor.GetProperties(Attribute[])' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetProperties(Attribute[]): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetProperties(Attribute[])' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetProperties(Attribute[])' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2046: Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetProperties(): Interface member 'System.ComponentModel.ICustomTypeDescriptor.GetProperties()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Microsoft.Identity.Json.Linq.JObject.System.ComponentModel.ICustomTypeDescriptor.GetProperties()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
ILLink : Trim analysis error IL2026: Microsoft.Identity.Json.Serialization.JsonTypeReflector.CanTypeDescriptorConvertString(Type,TypeConverter&): Using member 'System.ComponentModel.TypeDescriptor.GetConverter(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.
ILLink : Trim analysis error IL2067: Microsoft.Identity.Json.Serialization.JsonTypeReflector.CanTypeDescriptorConvertString(Type,TypeConverter&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The parameter 'type' of method 'Microsoft.Identity.Json.Serialization.JsonTypeReflector.CanTypeDescriptorConvertString(Type,TypeConverter&)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Serialization.JsonTypeReflector.GetAttribute<T>(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Microsoft.Identity.Json.Serialization.JsonTypeReflector.GetAttribute<T>(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Converters.KeyValuePairConverter.InitializeReflectionObject(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructor(Type[])'. The parameter 't' of method 'Microsoft.Identity.Json.Converters.KeyValuePairConverter.InitializeReflectionObject(Type)' 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.
ILLink : Trim analysis error IL2062: Microsoft.Identity.Client.MsalException.FromJsonString(String): Value passed to parameter '#0' of method 'System.Activator.CreateInstance(Type,Object[])' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionObject.Create(Type,MethodBase,String[]): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetMember(String,BindingFlags)'. The parameter 't' of method 'Microsoft.Identity.Json.Utilities.ReflectionObject.Create(Type,MethodBase,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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetChildPrivateFields(IList<MemberInfo>,Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetChildPrivateFields(IList<MemberInfo>,Type,BindingFlags)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetChildPrivateProperties(IList<PropertyInfo>,Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetChildPrivateProperties(IList<PropertyInfo>,Type,BindingFlags)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetDefaultConstructor(Type,Boolean): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors(BindingFlags)'. The parameter 't' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetDefaultConstructor(Type,Boolean)' 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.
ILLink : Trim analysis error IL2067: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetDefaultValue(Type): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'type' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetDefaultValue(Type)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetFields(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetFields(Type,BindingFlags)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetMemberInfoFromType(Type,MemberInfo): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags,Binder,Type,Type[],ParameterModifier[])'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetMemberInfoFromType(Type,MemberInfo)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetMemberInfoFromType(Type,MemberInfo): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors', 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields', 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.NonPublicNestedTypes', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties', 'DynamicallyAccessedMemberTypes.PublicEvents', 'DynamicallyAccessedMemberTypes.NonPublicEvents' in call to 'System.Type.GetMember(String,MemberTypes,BindingFlags)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetMemberInfoFromType(Type,MemberInfo)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetProperties(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetProperties(Type,BindingFlags)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetProperties(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'targetType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.GetProperties(Type,BindingFlags)' 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.
ILLink : Trim analysis error IL2065: Microsoft.Identity.Json.Utilities.ReflectionUtils.GetProperties(Type,BindingFlags): Value passed to implicit 'this' parameter of method 'System.Type.GetProperties(BindingFlags)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.ImplementsGenericDefinition(Type,Type,Type&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.ImplementsGenericDefinition(Type,Type,Type&)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.ReflectionUtils.IsMethodOverridden(Type,Type,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethods(BindingFlags)'. The parameter 'currentType' of method 'Microsoft.Identity.Json.Utilities.ReflectionUtils.IsMethodOverridden(Type,Type,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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.TypeExtensions.AssignableToTypeName(Type,String,Boolean,Type&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Microsoft.Identity.Json.Utilities.TypeExtensions.AssignableToTypeName(Type,String,Boolean,Type&)' 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.
ILLink : Trim analysis error IL2070: Microsoft.Identity.Json.Utilities.TypeExtensions.ImplementInterface(Type,Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Microsoft.Identity.Json.Utilities.TypeExtensions.ImplementInterface(Type,Type)' 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.
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataSet.WriteXmlSchema(DataSet,XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataSet.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataSet.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
ILLink : Trim analysis error IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataTable.GetXmlSchema()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.
ILLink : Trim analysis error IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataTable.ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
ILLink : Trim analysis error IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataTable.WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.
Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\sdk\6.0.400-preview.22301.10\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(109,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.
Expected behavior No build errors or warnings when building a self-contained exe.
Actual behavior Multiple errors, and very hard to workaround/fix manually.
Possible solution Most errors seems related to JSON deserialization, and .NET6 now supports source generation for this, so it should be possible to support this.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
One of the blockers for us (Git Credential Manager) from dropping .NET Framework on Windows (and going .NET6/7 etc) would be the ability to publish our app trimmed. Since MSAL is a hard dependency for us, this work would be really helpful for us! Would love to publish AOT compiled too in .NET 7 if MSAL can work.
Working on using System.Text.Json. Got most of the tests passing again. Sending PR soon.
@bgavrilMS what’s the minimum target framework you’re looking to support?
According to the support policy here:
As it’d be nice to just switch over to
System.Text.Jsonas its continually getting performance improvements.@bgavrilMS all you should need is for the build environment to install the .NET 6 SDK (for instance with GitHub Actions it’d be):
Though if you’re still building for an older target netcore app, you may need to install both SDKs? But you don’t have to change the multi-targeting unless you want to make specific optimizations for newer platforms (like .NET 6 wouldn’t need the
System.Text.JsonNuGet package as it’s included w/ .NET itself now).Net Core App 2.1 is out of support now, so it looks like Alex updated to 3.1 in his PR here as well
Please also consider that the Newtonsoft.JSON dependency is extremely large. Multiple megabytes, especially when AOT is enabled (which is a must in iOS apps). Using System.Text.Json would significantly reduce the app size, which does matter especially for mobile apps. The MS Graph library (which I assume is commonly used in combination with MSAL) already did the switch to System.Text.Json
Would it be possible to re-open this feature request?
Excellent bug. Just so happens that we are also exploring this area, as we want to make MSAL compile with NET7’s AOT compiler. Here’s are the notes that @pmaytak wrote on the subject.
Problem statement:
Possible solutions:
Add System.Text.Json package for supported targets, while keeping JSON.NET for older targets ? a. First need to research System.Text.Json feature and framework availability. i. Source generation is only for .NET 5+. How to choose reflection or source generation in System.Text.Json | Microsoft Docs/ ii. Differences with JSON.NET need to be verified. Migrate from Newtonsoft.Json to System.Text.Json - .NET | Microsoft Docs b. Need to look over what existing features we use from JSON.NET. i. There are 71 references to JSON.NET namespace in MSAL and tests projects. c. Ideally individual usages should be consolidated in JSON helper class and used from there. d. Add pre-processor flags to load the relevant implementations based on the target framework. e. Existing tests should be enough, but coverage should still be verified. f. ETA is at least 3+ days. Research of current used functionality is the most important part. Code changes should be easy once migration steps are defined.
Replace Newtonsoft.Json with System.Text.Json source code from https://github.com/dotnet/runtime/tree/main/src/libraries/System.Text.Json. a. The current System.Text.Json minimal requirements might not be a functional limitation and the code might simply work in 4.5.2 since it works in net 4.6.1 b. Same as above, except JSON.NET code will be removed.
Use System.Text.Json generator code a. We could pull the reflection less code generator into the repo and run it outside of minimal generation
Write your own code generation based on contract classes: a. Move json manipulation into data contract classes or multi b. Create a build task that would generate json string serializers using JsonDocument writers etc.
One of the challenges in estimating time are the unknowns that need to be researched - what exactly needs to be excluded in JSON.NET and making sure System.Text.Json supports everything that we use from JSON.NET.
Unity related work: [Feature Request] [L] Stop using reflection to deserialize JSON · Issue #2343 Update JSON.NET code to work with Unity. by pmaytak · Pull Request #2428 Remove the HAVE_CAS define so that Newtonsoft.Json never uses dynamic code generation as its not supported in Unity. by najadojo · Pull Request #2588
System.Text.Json framework support: .NET API Catalog (apisof.net) - Built-in: .NET 5+, .NET Core 3+ - Via Nuget package: .NET Core 2+, .NET Fx 4.6.1+, .NET Standard 2+