question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting NULL when using ResourceManager.GetString() with strings using placeholders

See original GitHub issue

I have a embedded Resource.resx file and a Resource.Designer.cs autogenerated containing many string resources, some of them have placeholders (i.e. “Hello, ‘{0}’”) and these are the ones that are returning null when calling from code, i.e. Resource.KeyName. This Resource.resx file exist in a library project with TargetFrameworks net452, netstandard2.0 and netstandard2.1. I’m dealing with this issue when I run my Test Project (net452, netcoreapp3.0, netcoreapp2.2) and make use of that Resource.

This issue is only happening when the tests are ran using net452 (I have tried with net472 also and behaves the same) with resources containing placeholders and compiling/running tests from CLI (dotnet test), when using VS it’s working fine. I had to add the following to my .csproj of the library because it was failing at compiling:

<GenerateResourceUsePreserializedResources>**true**</GenerateResourceUsePreserializedResources>

<PackageReference Include="System.Resources.Extensions">
      <Version>4.6.0-preview8.19405.3</Version>
</PackageReference>

SDK used: 3.0.100-preview8-013656

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rainersigwaldcommented, Sep 4, 2019

Thanks @danielValdezR! The fact that the second build is required is indicative of microsoft/msbuild#4553. I tried your repro on my machine with a preview9 build (3.0.100-preview9-014004) and all three TargetFrameworks pass tests. Another change means that System.Resources.Extensions is not required as often, so this specific repro project doesn’t require it, though that won’t be true of all .resx files.

I’m going to close this based on my results. If you see further bad behavior after updating to preview 9, please comment again and we can reopen and investigate.

0reactions
danielValdezRcommented, Sep 4, 2019

repro project: https://github.com/danielValdezR/ResourcesTest

Steps to reproduce: cd …\ResourcesTest\ResourcesTest.Tests

dotnet clean
dotnet build -- MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.
dotnet build
dotnet test -f netcoreapp3.0 -- should PASS
dotnet test -f net452 -- should FAIL

Log: https://github.com/danielValdezR/ResourcesTest/blob/master/log.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - ResourceManager.GetString returns null
I found the problem. It was a dump error I made. I gave wrong values while testing in DBVersion and fileDBVersion so when...
Read more >
Resourcemanager.GetString returns null
i mean when resourcemanager.getstring returns a string, then after that it doesnt return anything! it loads assembly correctly always! problem ...
Read more >
[Solved] NullReferenceException when using ...
I have assigned a string reference in the Inspector. This is the exact error I get: NullReferenceException: Object reference not set to an ......
Read more >
How to use placeholders in a string resource ...
As the resource holds the format, you need to populate it. string.Format(resourceLoader.GetString("MyPlaceholders"), "Hello", "World").
Read more >
Generated Access to .NET Resource Strings
To access the resource “ResourceId1”, you would use the following code: ResourceManager rm = new ResourceManger(); String result = ResourceId1.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found