Skip to content

StringValues implicit conversion to string should match ToString() #58223

@dougbu

Description

@dougbu

Description

Signature of static implicit operator string? (StringValues values) does not match public override string ToString() in the same struct. This may be due to a long-standing bug in the original StringValues implementation which could return null. We never handled that case higher in the stack i.e. we aren't expecting null from the implicit conversion.

Result in [main] Update dependencies from dotnet/efcore dotnet/runtime by dotnet-maestro · Pull Request #35547 · dotnet/aspnetcore (github.com) will be a lot of redundant-seeming .ToString() calls. That will likely result in needless attempts to remove them later because we all "know" implicit conversions to string and ToString() are semantically identical.

Please update https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Primitives/src/StringValues.cs#L72-L75 to use ToString() and return string. I can submit a PR if agreed.

Configuration

I'm currently building with Microsoft.Extensions.Primitives v7.0.0-alpha.1.21425.1 but the PR has probably moved on from that. Not seeing a change in the StringValues code however.

Problem is new in 7.0.0 but otherwise not specific to a configuration.

Regression?

Kind-of. We didn't need the ToString() calls in existing ASP.NET Core code.

Other information

Work around is to add ToString() but the number of calls required is very quickly piling up as I work on [main] Update dependencies from dotnet/efcore dotnet/runtime by dotnet-maestro · Pull Request #35547 · dotnet/aspnetcore (github.com)](dotnet/aspnetcore#35547).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions