Generating a string resource entry in a resource file (Resources.resx) and deleting the entry again by the VS string resource editor results in a corrupted .resx file. The resource editor reports 'ResX file Data at the root level is invalid. Line 1, position 1, cannot be parsed.'.
This can be reproduced by creating a small C# console application:
Add a string resource manually ("Hello1").
Insert a string literal in the Main method of Program.cs: Console.WriteLine("Hello2");
Use the CodeRush for Roslyn 'Extract String to Resource' refactoring tool and convert "Hello2" to a string resource.
The program compiles without errors and behaves correctly.
After deleting "Hello2" again, the Resources.resx file is corrupted, compilation is not possible.
It does not happen when deleting the manually added entry "Hello1".
I could reproduce this behavior with Visual Studio 2015 and 2017.
Hi,
Thank you for your report. I have managed to reproduce this problem locally and we will fix it in our future builds.
As a workaround, I suggest that you accept a green link (a rectangle around the name of a resource) after applying the Extract String to Resource refactoring and renaming the name of a created resource. You can do this by pressing the Enter key. In this case, the problem will not be reproduced.
Andrew,
this works fine and is an acceptable workaround.
Thanks for your help!
Gerhard
You are welcome!
I have a good news. We have to rewrite the logic of this refactoring and starting with the 16.2.7 version, this problem will be fixed. Now this refactoring does not apply changes while a resource name will not be accepted by the Enter key.