Runtime: How to get all keys in resourceManager?

Created on 27 May 2016  路  11Comments  路  Source: dotnet/runtime

Before i could do something like this
var result = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

but now i cant find a way to get all keys in ResourceManager in RC2,

Thank you for your help.

area-System.Resources question

Most helpful comment

@ramarag is GetResourceSet going to get implemented? In my own case I want to be able to return all keys and values in resources file to the client for faster lookup.

All 11 comments

There is no single API that does this. Can you please elaborate your scenario so that we can think about adding a enumeration API.

For the time being you could look at using ResourceReader, a StreamingResourceManager example can be found in https://gist.github.com/ramarag/6e6f58a210dd00745582#file-streambasedresourcemanager-L34

In RC1, System.Resources.ResourceManager, has a GetResourceSet, that it returns a ResourceSet with all the resources,

/// <summary>Retrieves the resource set for a particular culture.</summary>
    /// <returns>The resource set for the specified culture.</returns>
    /// <param name="culture">The culture whose resources are to be retrieved. </param>
    /// <param name="createIfNotExists">true to load the resource set, if it has not been loaded yet; otherwise, false. </param>
    /// <param name="tryParents">true to use resource fallback to load an appropriate resource if the resource set cannot be found; false to bypass the resource fallback process. (See the Remarks section.)</param>
    /// <exception cref="T:System.ArgumentNullException">The <paramref name="culture" /> parameter is null. </exception>
    /// <exception cref="T:System.Resources.MissingManifestResourceException">
    /// <paramref name="tryParents" /> is true, no usable set of resources has been found, and there are no default culture resources. </exception>
    [SecuritySafeCritical]
    [MethodImpl(MethodImplOptions.NoInlining)]
    public virtual ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents);

But now i cant find a way to do the same in RC2

Can you share your RC1 project. I believe this Api was unavailable even in RC1,unless you were building your application directly against mscorlib.dll or were using reflection

I cannot share the project, but i used this (mscorlib)
https://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.getresourceset(v=vs.110).aspx

it worked for me in RC1 but now i cannot do it.

if it is not supported, it will be good to have a way to have a way to get a list with all the keys and values in the resource, and not only one.

You are not supposed to build against mscolrib for .Net Core. As I mentioned above this scenario is not supported on .Net Core. But we should be happy to look into adding the capability if we get to know more about what you would like to do with the enumerated resources.

cc @tarekgh

I use it to get a custom list of countries(and their code), and a custom list of languages(and their code) in a resx, it can be useful when you want to get a lot of resources, instead of going resource by resource, you can get all the resources and filter them in your own code if you need to, for example you will be able get all the resources and then filter the resources that contains in their value/key something without knowing the full names of the keys you want in your code. Sorry for my grammar.

@ramarag is GetResourceSet going to get implemented? In my own case I want to be able to return all keys and values in resources file to the client for faster lookup.

In my scenario we use(d) it to extract all available locals and 'exposed' it to clients (by means of fetching the list using an ajax request). Any alternatives that you can suggest?

The old Resources APIs are getting added for netstandard2.0, which will solve this issue
https://github.com/dotnet/corefx/issues/11769

Has this option been added yet? I've created a new ASP.NET Core Web Application but it appears I can't use the ResourceManager.GetResourceSet command.

I need this too. Analysis of which strings are and aren't actually used in our project. Because of the way our project is set up, checking references is not an option. We could parse the XML file manually, but this would be a lot smoother.

Was this page helpful?
0 / 5 - 0 ratings