Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IStringLocalizer error: Input string was not in a correct format #55706

Closed
1 task done
yedajiang44 opened this issue May 14, 2024 · 6 comments
Closed
1 task done

IStringLocalizer error: Input string was not in a correct format #55706

yedajiang44 opened this issue May 14, 2024 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@yedajiang44
Copy link

yedajiang44 commented May 14, 2024

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label May 14, 2024
@martincostello
Copy link
Member

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

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

@yedajiang44
Copy link
Author

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?

@martincostello
Copy link
Member

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

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

@yedajiang44
Copy link
Author

yedajiang44 commented May 14, 2024

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

@mkArtakMSFT
Copy link
Member

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.

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@yedajiang44
Copy link
Author

got it. thanks reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants