commandlineparser / commandlineparser/commandline
IL2104: Assembly 'CommandLine' produced trim warnings
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 478
- PR merge metrics
- No merged PRs in 30d
Description
I'm getting an error message indicating the library is using a method that is incompatible with [application trimming](https://aka.ms/dotnet-illink/libraries).
From what I can see, the specific issue is with the `System.ComponentModel.TypeDescriptor.GetConverter` method. Generic `TypeConverters` may require the generic types to be annotated. An option would be to use `GetConverterTrimUnsafe` if we can be sure the converter is trim compatible (type is not `Nullable`).
```cs
// CommandLine.Core.TypeConverter.ConvertString
private static object ConvertString(string value, Type type, CultureInfo conversionCulture)
{
try
{
return Convert.ChangeType(value, type, conversionCulture);
}
catch (InvalidCastException)
{
// Required for converting from string to TimeSpan because Convert.ChangeType can't
return System.ComponentModel.TypeDescriptor.GetConverter(type).ConvertFrom(null, conversionCulture, value);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at CommandLine.Core.TypeConverter.ConvertString and inspect the TypeDescriptor.GetConverter call shown in the report. Reproduce the application-trimming warning, then determine whether the conversion path is trim-compatible and verify that the warning is resolved without breaking string-to-TimeSpan conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100