RequestLocalizationMiddleware does not handle CultureInfo.InvariantCulture since version 8
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
The RequestLocalizationMiddleware sets the culture to default even if the ```RequestLocalizationOptions``` supports ```CultureInfo.InvariantCulture``` since version 8.
Example:
```c#
builder.Services.Configure(options => {
var supportedCultures = new[]
{
CultureInfo.InvariantCulture,
CultureInfo.GetCultureInfo("fr"),
CultureInfo.GetCultureInfo("en"),
};
options.DefaultRequestCulture = new(supportedCultures[1]);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.RequestCultureProviders =
[
new DefaultRequestCultureProvider()
];
});
public class DefaultRequestCultureProvider : IRequestCultureProvider
{
public Task DetermineProviderCultureResult(HttpContext httpContext)
{
var result = new ProviderCultureResult(culture: CultureInfo.InvariantCulture.Name, uiCulture: CultureInfo.CurrentUICulture.Name);
return Task.FromResult(result);
}
}
```
At the end, ```CultureInfo.CurrentCulture``` was always the ```DefaultRequestCulture``` instead of ```CultureInfo.InvariantCulture```.
Note: this code worked until version 8
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.