Sebastian Negraszus
Sebastian Negraszus

Reputation: 12215

Why does ReSharper complain about this use of ResourceLoader.GetString?

I have a Windows 8 app that I localize as described in the MSDN. My resource files use the default names ("Resources.resw") and locations ("Strings\en-US" etc.).

enter image description here

When I access the resources via ResourceLoader, then ReSharper complains. Example:

private readonly ResourceLoader _resourceLoader = new ResourceLoader();

private void DoSomething()
{
    string s = _resourceLoader.GetString("TestEntry");
}

enter image description here

ReSharper complains that I'm creating an ambiguous reference, because there are several "TestEntry" keys in several resource files. Duh. That's the whole point. The resource management should automatically use the correct resource, and it does indeed.

So, why does ReSharper complain? Is it a bug in ReSharper or is there really something wrong?

By the way: ReSharper recommends (among other fairly useless things) offers to put resource: before the key string, like _resourceLoader.GetString(resource: "TestEntry") (and then complains that it's redundant). This makes the ReSharper warning disappear. What does that do? Is it an improvement?

Edit: Oh my! I somehow thought resource: is some special syntax, but it's just a named method argument...

Upvotes: 10

Views: 939

Answers (1)

Peter Pompeii
Peter Pompeii

Reputation: 1445

Instead of constructing a new ResourceLoader, try using the static GetForCurrentView() method to retrieve the appropriate ResourceLoader.

private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView();

private void DoSomething()
{
    string s = _resourceLoader.GetString("TestEntry");
}

Upvotes: 1

Related Questions