© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
no >> body

❔ Localization behavior in tests

I've been facing an issue with xUnit integration tests for my ASP.NET Core application and I'm struggling to find a solution.
We use localization in our app for translating various responses. Everything works perfectly fine when I run the tests on my local machine. However, when I try to run them in our CI/CD pipeline on GitLab, the tests fail.
Initially, I encountered a
System.Globalization.CultureNotFoundException
System.Globalization.CultureNotFoundException
with a message about the invariant culture being the only supported one in globalization-invariant mode. I managed to solve this issue by adding
<InvariantGlobalization>false</InvariantGlobalization>
<InvariantGlobalization>false</InvariantGlobalization>
to my test project file.
The current problem I'm facing is a
System.ArgumentException
System.ArgumentException
in a method where we use
IStringLocalizer
IStringLocalizer
. The error message states: A message must be specified when calling
WithMessage
WithMessage
.
Here is a code where this error happens:
LocalizedString enumRangeErrorMessage = errorMessagesLocalizer[$"{ErrorMessageIdentifiers.ValidatorSection}:{ErrorMessageIdentifiers.EnumRange}"];
RuleFor(x => x.OrderBy)
    .Must(x => EnumHelper.TryParseWithMemberName<PaymentSystemAccountOrderBy>(x, out _))
    .WithMessage(enumRangeErrorMessage)
    .When(x => !string.IsNullOrEmpty(x.OrderBy));
LocalizedString enumRangeErrorMessage = errorMessagesLocalizer[$"{ErrorMessageIdentifiers.ValidatorSection}:{ErrorMessageIdentifiers.EnumRange}"];
RuleFor(x => x.OrderBy)
    .Must(x => EnumHelper.TryParseWithMemberName<PaymentSystemAccountOrderBy>(x, out _))
    .WithMessage(enumRangeErrorMessage)
    .When(x => !string.IsNullOrEmpty(x.OrderBy));

Where errorMessagesLocalizer is just
IStringLocalizer
IStringLocalizer
.
The odd part is that this exception only occurs in the pipeline. The tests run successfully on my local machine.
I've checked that the paths to my resources are correct and that they are included in the build output. I've tried replicating the CI/CD environment locally to debug the issue, but I can't reproduce it.

I'm running out of ideas here. Does anyone have any suggestions on what could be going wrong or what else I could try?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ A problem with tracking behavior in unit tests
C#CC# / help
2y ago
Localization in Clean Architectire
C#CC# / help
7mo ago
❔ Environment variables in tests
C#CC# / help
3y ago
✅ .NET Localization Culture Fallback
C#CC# / help
3y ago