String resource containing only whitespace characters are loaded as blank strings
See original GitHub issue.NET version
Replicated on .NET Core 3 and all later versions.
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
I did not try this with versions prior to .NET Core 3.
Issue description
If a localized property’s value is set to a string that only contains whitespace characters, ComponentResourceManager methods such as ApplyResources or GetString retrieve it as a blank string. This is a breaking change for .NET Framework applications where this is not the case.
I could not find this change documented anywhere, or any issues related to it.
The XML generated for the property is the same in both .NET FX and .NET Core/5+:
<data name="label1.Text" xml:space="preserve">
<value> </value>
</data>
Steps to reproduce
I attached a solution containing two identical forms in .NET Framework 4.8 and .NET 6. T1080450.zip
To replicate:
- Create a new project using the Windows Forms App template.
- Set the main form’s Localizable property to true.
- Add a label and set its Text property to
- Debug the project and check the value of this property after it is set in the InitializeComponent method.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
android - How to keep the spaces at the end and/or ...
I wanted to leave a blank at the end of a resource string ... I just use the UTF code for space "\u0020"...
Read more >ResourceManager.GetString() returns "" when value only ...
It worked fine when I added a non-space character to the value, but . ... String resource containing only whitespace characters are loaded...
Read more >Remove useless whitespace from styled string
The answer is to put the newlines at the start of each line, directly before the text. <string name="about_text"><big><b>About</b></big> ...
Read more >Checking for Empty or Blank Strings in Java
If a string only consists of whitespace, then we call it blank. For Java, whitespaces are characters, like spaces, tabs, and so on....
Read more >Program to Check if String is Empty in Python
A blank string contains whitespaces while an empty string does not contain any characters or whitespace. The method where White spaces in strings...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is issue for https://github.com/dotnet/runtime
Tests which should be extended located here https://github.com/dotnet/runtime/blob/da5888aa4d7f8cac2519d5d35d7d8f59385fc6e8/src/libraries/System.ComponentModel.TypeConverter/tests/ComponentResourceManagerTests.cs
I guess that’s a wrap. Thanks @kant2002!