Skip to content

StringArgumentValue.ConvertTo() should convert enum's case insensitive #431

@prochnowc

Description

@prochnowc

When using the OpenTelemetry sink while hosting my app in Aspire I receive the following exception:

System.ArgumentException: Requested value 'grpc' was not found.
   at System.Enum.TryParseByName[TStorage](RuntimeType enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, TStorage& result)
   at System.Enum.TryParseByValueOrName[TUnderlying,TStorage](RuntimeType enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, TUnderlying& result)
   at System.Enum.TryParse(Type enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, Object& result)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at Serilog.Settings.Configuration.StringArgumentValue.ConvertTo(Type toType, ResolutionContext resolutionContext)
   at Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass23_2.<CallConfigurationMethods>b__3(<>f__AnonymousType9`2 <>h__TransparentIdentifier0)
   at System.Linq.Enumerable.SelectListPartitionIterator`2.Fill(IList`1 source, Span`1 destination, Func`2 func, Int32 sourceIndex)
   at System.Linq.Enumerable.SelectListPartitionIterator`2.ToList()
   at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup`2 methods, IReadOnlyCollection`1 configurationMethods, Object receiver)
   at Serilog.Settings.Configuration.ConfigurationReader.ApplySinks(LoggerConfiguration loggerConfiguration)
   at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
   at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)
   at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, ConfigurationReaderOptions readerOptions)

This is because Aspire sets the environment variable OTEL_EXPORTER_OTLP_PROTOCOL to grpc which is not known by the OtlpProtocol enum.

IMHO the StringArgumentValue.ConverTo() method should always try to convert enums case insensitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions