Localization icon indicating copy to clipboard operation
Localization copied to clipboard

Calling IStringLocalizer<T>.GetAllStrings() throws MissingManifestResourceException after upgrading to dotnet core 2.0

Open jfiskvik opened this issue 9 years ago • 19 comments

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.

jfiskvik avatar Aug 21 '17 16:08 jfiskvik

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?

hishamco avatar Aug 21 '17 17:08 hishamco

Sample repo reproducing the issue: https://github.com/jfiskvik/LocalizationSample

jfiskvik avatar Aug 22 '17 08:08 jfiskvik

@ryanbrandenburg can you take a look?

Eilon avatar Aug 23 '17 07:08 Eilon

The same issue as @jfiskvik here. Waiting for response...

EugenioSerrano avatar Aug 24 '17 19:08 EugenioSerrano

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

marcusien avatar Sep 01 '17 09:09 marcusien

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).

barynov avatar Sep 01 '17 15:09 barynov

@ryanbrandenburg is this the one your PR created for?

hishamco avatar Sep 06 '17 20:09 hishamco

Closed by #413.

ryanbrandenburg avatar Sep 07 '17 17:09 ryanbrandenburg

@ryanbrandenburg - should this be marked as bug + 3 - Done?

Eilon avatar Sep 07 '17 21:09 Eilon

Fixed.

ryanbrandenburg avatar Sep 07 '17 21:09 ryanbrandenburg

Hi Ryan. Do you know when this fix will become part of a update to install in production ?

EugenioSerrano avatar Sep 07 '17 21:09 EugenioSerrano

@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.

Eilon avatar Sep 07 '17 22:09 Eilon

Thank You @Eilon . I am using the workaround commented by @barynov having a neutral resx file in order to get access to all keys.

EugenioSerrano avatar Sep 07 '17 22:09 EugenioSerrano

I'm looking to retrieve all localizedstrings and return to a calling javascript library, is there any workaround for this ?

AdnanCukur avatar Nov 10 '17 14:11 AdnanCukur

@AdnanCukur could you please file a new issue and describe what you want in more details

hishamco avatar Nov 10 '17 17:11 hishamco

@hishamco I want to know if there exists a workaround to make IStringLocalizer.GetAllStrings() work, that I can use in production right now

AdnanCukur avatar Nov 10 '17 22:11 AdnanCukur

@AdnanCukur I expect it works after the PR #413?!!

hishamco avatar Nov 11 '17 15:11 hishamco

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 avatar Dec 29 '17 12:12 MookieFumi

@MookieFumi this is raised again on #433

hishamco avatar Dec 29 '17 13:12 hishamco