question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Microsoft.Identity.Client doesn't support IL Trimming

See original GitHub issue

.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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
azchohficommented, Jun 27, 2022

Working on using System.Text.Json. Got most of the tests passing again. Sending PR soon.

2reactions
michael-hawkercommented, Jun 22, 2022

@bgavrilMS what’s the minimum target framework you’re looking to support?

According to the support policy here:

Support for .NET Framework 4.5.2, 4.6, and 4.6.1 ended on April 26, 2022. Customers and developers must have completed the in-place update to .NET Framework 4.6.2 or later by April 26, 2022 to continue receiving technical support and security updates.

As it’d be nice to just switch over to System.Text.Json as its continually getting performance improvements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trimming options - .NET
Enable trim analysis warnings. Trimming removes IL that is not statically reachable. Apps that use reflection or other patterns that create ...
Read more >
MsalError Class (Microsoft.Identity.Client)
You are trying to authenticate with the broker but MSAL is unable to read the response from the broker. Mitigation. The currently installed...
Read more >
Resolved issues in Windows 11, version 22H2
If your Windows device is already experiencing this issue, you might need to contact customer support for the developer of the app you...
Read more >
Fix NDR error 550 5.7.1 in Exchange Online
Microsoft doesn't support using more than one MX record for a domain that's enrolled in Exchange Online. Your domain's SPF record has a...
Read more >
Try the new System.Text.Json source generator - .NET Blog
In .NET 6.0, we are shipping a new C# source generator to help ... Reflection is a problem for startup, memory usage, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found