dotnet/aspnetcore

IStringLocalizer error: Input string was not in a correct format

yedajiang44 opened this issue · 6 comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Input string was not in a correct format. Failure to parse near offset 1. Expected an ASCII digit.

Expected Behavior

format string

Steps To Reproduce

  1. create resx file
  2. create key and value{dateTime}: System is running.
  3. localizer.GetString("{dateTime}: System is running.", DateTimeOffset.Now)

If change dateTime to 0 with resx file and code, that is running well.

localizer.GetString("{0}: System is running.", DateTimeOffset.Now)

Exceptions (if any)

No response

.NET Version

8.0

Anything else?

No response

I think the issue here is you're using a named parameter, not an index.

Your string should be {0}: System is running.

I think the issue here is you're using a named parameter, not an index.

Your string should be {0}: System is running.

Yes, named parameter cannot be used? must be an index?

I believe so, as ultimately string.Format() is used:

var value = string.Format(CultureInfo.CurrentCulture, format ?? name, arguments);

It's a pity! Is it possible to consider supporting named parameters like logger.Debug("{dateTime}: System is running.",DateTimeOffset.Now)?

Thanks for contacting us.
While this may be a great idea, it is not aligned with our long-term vision to make it part of the framework. For many other ideas which don't belong to the framework we encourage the community to build and ship on their own, contributing to the expanding .NET Ecosystem.

You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

got it. thanks reply!