question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(InvalidCharacterError with Datetime (Localized?)

See original GitHub issue

Which version of FluentValidation are you using? Please specify which version of FluentValidation you’re using. 9.1.1

Which version of ASP.NET are you using? If you are using FluentValidation with ASP.NET, please provide the version of ASP.NET that you’re using (eg .NET Core 2.1, NET Core 3.1 etc) ASP.Net Blazor 3.1 On FireFox 79.0

Describe the issue that you’re having A clear and concise description of the issue that you’re having, steps to reproduce, and sample code to reproduce the issue.

When I use a date with fluentvalidation, it always fail with an error:

System.AggregateException: One or more errors occurred. (InvalidCharacterError: String contains an invalid character) —> System.InvalidOperationException: InvalidCharacterError: String contains an invalid character at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)

My OS is in french, I tried to set CultureInfo.DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture in english even with CultureInfo.InvariantCulture; it don’t work.

The classes used:

    public class Person
    {
        public string PersonName { get; set; }
        public DateTime? PersonBirthDate { get; set; }

    }

    public class PersonValidator : AbstractValidator<Person>
    {
        public PersonValidator()
        {
            RuleFor(r => r.PersonName).NotEmpty().WithMessage("The name counld not be empty!");
            RuleFor(r => r.PersonBirthDate).Must(BirthDateValidator).WithMessage("Error date!");

        }

        private bool BirthDateValidator(DateTime? date)
        {
            return !(date == null || (date < DateTime.Now.AddYears(-99) || date > DateTime.Now.AddYears(-18)));
        }
    }

GitHub Source: https://github.com/frablaser/ErrorDateFireFox

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
frablasercommented, Aug 18, 2020

This is a Mozilla thing, it store the culture in the cookies… If you flush the recent cookies it should works.

I’m totally stuck… With Blazor Server side, I have to manipulate the cookies to get rid of the culture, it will totally disturb all my web site, that’s not a solution. It’s funny that in 2020 there still some date unmanagement like that. I have to drop FV or my site Localization… 🙄 I’ll wait for the Blazor team to see if the can fix it…

Thanks anyway Jeremy for your support, the day where I’ll do money with my site, I’ll come back to pay you a good tip.

Best regards Francis

0reactions
frablasercommented, Aug 18, 2020

Also I’ll point out that the razor integration with FluentValidation (the <FluentValidator> component) is not something we provide - so it might be worth reaching out to the authors of this too to see if they’re able to shed any light on it.

I’ll will knock on that door too! Why not! 😉👍

Regards

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Datetime Localization Bug?
If you send US dates through DateTime.TryParse, it uses the local machine's locale to parse it. It fails if the date is not...
Read more >
Date.prototype.toLocaleDateString() - JavaScript | MDN
A string representing the date portion of the given Date instance according to language-specific conventions. In implementations with Intl.
Read more >
The Definitive Guide to DateTime Manipulation
Time and date manipulation is notoriously difficult. Developers encountering time zone rules, leap seconds, differences in locale-specific formatting are ...
Read more >
Intl.DateTimeFormat() constructor - JavaScript - MDN Web Docs
The Intl.DateTimeFormat() constructor creates Intl.DateTimeFormat objects. ... Specify default date formatting for language (locale).
Read more >
Javascript Dates Manipulation with Date-fns
Date -fns supports I18n to internationalize date functions and display localized formatted dates. You need to use the require('date-fns/locale'); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found