I'm developing backend application using .NET core 3.1. I moved CommonResource from my old project (.NET core 2.1) where works fine. I want to obtain value for key in specified culture. Implementation of CommonResource:
public class CommonResource : ICommonResource
{
private readonly IStringLocalizer<SharedResource> _localizer;
public CommonResource(
IStringLocalizer<SharedResource> localizer)
{
_localizer = localizer;
}
#region ICommonResource Members
#region General
public string AppName(
string language)
=> GetString(language, nameof(AppName));
#endregion
#endregion
/// <summary>
/// Dispose of class and parent classes
/// </summary>
public void Dispose()
=> GC.SuppressFinalize(this);
private string GetString(
string language,
string name)
{
var currentCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo(language);
var value = _localizer[name];
CultureInfo.CurrentCulture = currentCulture;
// TEST - check all string
//var result = _localizer.GetAllStrings();
return value;
}
}
LocalizationExtensions with AddDefaultLocalization method:
public static class LocalizationExtensions
{
private const bool AcceptLanguageHeaderRequestCultureProvider = false;
private static readonly CultureInfo CultureInfoEnUs = new CultureInfo("en-US");
private static readonly CultureInfo CultureInfoPlPl = new CultureInfo("pl-PL");
private static readonly CultureInfo DefaultRequestCulture = CultureInfoEnUs;
private static readonly CultureInfo[] SupportedCultures =
{
CultureInfoEnUs,
CultureInfoPlPl
};
public static void AddDefaultLocalization(
this IServiceCollection serviceCollection)
{
serviceCollection.AddLocalization();
serviceCollection.Configure<RequestLocalizationOptions>(
options =>
{
options.DefaultRequestCulture = new RequestCulture(DefaultRequestCulture, DefaultRequestCulture);
options.SupportedCultures = SupportedCultures;
if (!AcceptLanguageHeaderRequestCultureProvider)
{
//https://stackoverflow.com/questions/44480759/asp-net-core-default-language-is-always-english
options.RequestCultureProviders = new List<IRequestCultureProvider>
{
new QueryStringRequestCultureProvider(),
new CookieRequestCultureProvider()
};
}
});
}
}
My SharedResources are in Resources path (Build Action: Embedded resource and Access Modifier: No code generation).

Unfortunately invoke _localizer.GetAllStrings(); generates exception "No manifests exist for the current culture".
I tried many solutions e.g. move SharedResources to root path or install extra nuget package, but nothing helped.
Do you have any idea why in new version .net core this problem exists? Thanks for help!