Skip to content

Multiple errors when trying to ILLink/Trim a console app that uses Spectre. #955

@azchohfi

Description

@azchohfi

Information

  • OS: Windows
  • Version: 0.44.0
  • Terminal: Windows Terminal

Describe the bug
When trying to use Spectre on a console app that targets .NET6, and trying to build a self-contained library, I get multiple ILLink errors, such as IL2070, IL2072, IL2067, IL2072, IL2026, and IL2087.

To Reproduce
Reference Spectre.Console 0.44.0 from a console app, use something from Spetre, and build with PublishTrimmed=True, PublishSingleFile=True, "--self-contained -r win-x64 -f net6.0". Multiple errors.

Expected behavior
Builds and works fine.

Additional context

/_/src/Spectre.Console/Cli/Internal/CommandBinder.cs(10,37): Trim analysis error IL2070: Spectre.Console.Cli.CommandBinder.Bind(CommandTree,Type,ITypeResolver): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors()'. The parameter 'settingsType' of method 'Spectre.Console.Cli.CommandBinder.Bind(CommandTree,Type,ITypeResolver)' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs(34,9): Trim analysis error IL2072: Spectre.Console.Cli.CommandConstructorBinder.CreateSettings(CommandValueLookup,ConstructorInfo,ITypeResolver): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Activator.CreateInstance(Type,Object[])'. The return value of method 'System.Reflection.MemberInfo.DeclaringType.get' 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.
/_/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs(76,17): Trim analysis error IL2072: Spectre.Console.Cli.CommandParameter.Assign(CommandSettings,ITypeResolver,Object): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Spectre.Console.Cli.PairDeconstructorAttribute.Type.get' 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.
/_/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs(123,17): Trim analysis error IL2072: Spectre.Console.Cli.CommandParameter.Assign(CommandSettings,ITypeResolver,Object): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Spectre.Console.Cli.CommandParameter.ParameterType.get' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs(34,9): Trim analysis error IL2067: Spectre.Console.Cli.CommandPropertyBinder.CreateSettings(ITypeResolver,Type): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'settingsType' of method 'Spectre.Console.Cli.CommandPropertyBinder.CreateSettings(ITypeResolver,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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs(97,13): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueBinder.GetFlag(CommandParameter,Object): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Spectre.Console.Cli.CommandParameter.ParameterType.get' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs(48,13): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueBinder.GetLookup(CommandParameter,ITypeResolver,Object): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Spectre.Console.Cli.PairDeconstructorAttribute.Type.get' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(133,17): Trim analysis error IL2026: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(133,17): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The return value of method 'System.Type.GetElementType()' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(153,17): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The return value of method 'Spectre.Console.Cli.IFlagValue.Type.get' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(153,17): Trim analysis error IL2026: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(156,13): Trim analysis error IL2026: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(156,13): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueResolver.GetConverter(CommandValueLookup,CommandValueBinder,ITypeResolver,CommandParameter): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The return value of method 'Spectre.Console.Cli.CommandParameter.ParameterType.get' 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.
/_/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs(34,21): Trim analysis error IL2072: Spectre.Console.Cli.CommandValueResolver.GetParameterValues(CommandTree,ITypeResolver): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Spectre.Console.Cli.CommandParameter.ParameterType.get' 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.
/_/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs(21,40): Trim analysis error IL2070: Spectre.Console.Cli.ConfigurationHelper.GetGenericTypeArguments(Type,Type,Type[]&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Spectre.Console.Cli.ConfigurationHelper.GetGenericTypeArguments(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.
/_/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs(63,9): Trim analysis error IL2067: Spectre.Console.Cli.DefaultPairDeconstructor.GetConverter(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The parameter 'type' of method 'Spectre.Console.Cli.DefaultPairDeconstructor.GetConverter(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.
/_/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs(63,9): Trim analysis error IL2026: Spectre.Console.Cli.DefaultPairDeconstructor.GetConverter(Type): 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.
/_/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs(33,17): Trim analysis error IL2067: Spectre.Console.Cli.DefaultPairDeconstructor.Spectre.Console.Cli.IPairDeconstructor.Deconstruct(ITypeResolver,Type,Type,String): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'valueType' of method 'Spectre.Console.Cli.DefaultPairDeconstructor.Spectre.Console.Cli.IPairDeconstructor.Deconstruct(ITypeResolver,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.
/_/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs(408,77): Trim analysis error IL2070: Spectre.Console.ExceptionFormatter.<TryResolveStateMachineMethod>g__GetDeclaredMethods|13_0(IReflect): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.IReflect.GetMethods(BindingFlags)'. The parameter 'type' of method 'Spectre.Console.ExceptionFormatter.<TryResolveStateMachineMethod>g__GetDeclaredMethods|13_0(IReflect)' 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.
/_/src/Spectre.Console/Cli/Internal/Composition/Activators.cs(111,37): Trim analysis error IL2070: Spectre.Console.Cli.ReflectionActivator.GetGreediestConstructor(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Type.GetConstructors()'. The parameter 'type' of method 'Spectre.Console.Cli.ReflectionActivator.GetGreediestConstructor(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.
/_/src/Spectre.Console/Internal/TypeConverterHelper.cs(26,9): Trim analysis error IL2087: Spectre.Console.TypeConverterHelper.GetTypeConverter<T>(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The generic parameter 'T' of 'Spectre.Console.TypeConverterHelper.GetTypeConverter<T>()' 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.
/_/src/Spectre.Console/Internal/TypeConverterHelper.cs(26,9): Trim analysis error IL2026: Spectre.Console.TypeConverterHelper.GetTypeConverter<T>(): 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.
/_/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs(28,13): Trim analysis error IL2067: Spectre.Console.Cli.TypeResolverAdapter.Resolve(Type): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'type' of method 'Spectre.Console.Cli.TypeResolverAdapter.Resolve(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.

Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo 🕑

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions