Calling IStringLocalizer<T>.GetAllStrings() throws MissingManifestResourceException after upgrading to dotnet core 2.0
I have a controller which looks like this;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
namespace Vebono.EstateHandling.Web.Controllers
{
[Produces("application/json")]
[Route("api/[controller]")]
public class TranslationsController : Controller
{
private readonly IStringLocalizer<SharedResource> _localizer;
public TranslationsController(IStringLocalizer<SharedResource> localizer)
{
_localizer = localizer;
}
[HttpGet]
public ActionResult List()
{
Dictionary<string, string> translations = _localizer.GetAllStrings().ToDictionary(x => x.Name, x => x.Value);
return new JsonResult(translations);
}
}
}
I call the list method from an angular app in order to have one (shared) set of translations for both front-end and back-end. Prior to upgrading to dotnet core 2.0 it worked as expected, but now it throws a MissingManifestResourceException. The class SharedResource is just a dummy representing my resource files named SharedResource.en-GB.resx etc. Creating a (default) SharedResource.resx-file gets rid of the exception, but then the name/values I get back is from that file, not from the one representing the current culture.
This remind me with an old bug which @ryanbrandenburg made a temporary fix for it. But it's strange that it show up again
Could you please provide a sample repo that producing the issue?
Sample repo reproducing the issue: https://github.com/jfiskvik/LocalizationSample
@ryanbrandenburg can you take a look?
The same issue as @jfiskvik here. Waiting for response...
Exactly the same problem for me. Works totally fine with 1.1,1.2 and 1.3 versions and it does not work anymore since i just made an upgrade to 2.0.0
I have the same issue. I tried to debug it, looks like AssemblyResourceStringProvider.GetAssembly cannot load a satellite assembly for en culture because Assembly.Load fails. The workaround that I applied is to temporary create a neutral resource and then use GetAllStrings(true).
@ryanbrandenburg is this the one your PR created for?
Closed by #413.
@ryanbrandenburg - should this be marked as bug + 3 - Done?
Fixed.
Hi Ryan. Do you know when this fix will become part of a update to install in production ?
@EugenioSerrano this is for our 2.1.0 release, which is still in the early stages. We'll have an official preview of it later this year.
If you're running into a specific issue right now that you want fixed, we can look at suggesting workarounds.
Thank You @Eilon . I am using the workaround commented by @barynov having a neutral resx file in order to get access to all keys.
I'm looking to retrieve all localizedstrings and return to a calling javascript library, is there any workaround for this ?
@AdnanCukur could you please file a new issue and describe what you want in more details
@hishamco I want to know if there exists a workaround to make IStringLocalizer
@AdnanCukur I expect it works after the PR #413?!!
The same issue as @jfiskvik and @EugenioSerrano here.
var strings = _sharedLocalizer.GetAllStrings();
Message: No manifests exist for the current culture.
StackTrace:
at Microsoft.Extensions.Localization.ResourceManagerStringLocalizer.GetResourceNamesFromCultureHierarchy(CultureInfo startingCulture)
at Microsoft.Extensions.Localization.ResourceManagerStringLocalizer.<GetAllStrings>d__15.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
> dotnet --info
Herramientas de la línea de comandos .NET (2.1.3)
Product Information:
Version: 2.1.3
Commit SHA-1 hash: a0ca411ca5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.3\
Microsoft .NET Core Shared Framework Host
Version : 2.0.4
Build : 7f262f453d8c8479b9af91d34c013b3aa05bc1ff
Waiting for response...
@MookieFumi this is raised again on #433