- 
                Notifications
    You must be signed in to change notification settings 
- Fork 834
Description
When you rename a symbol that exists in another file that is open with pending changes, the rename operation is computed using the character positions of the unsaved file. This means if you've added any lines or changed target symbol positions in the target files, the replace operation will overwrite any text that existed at the old offsets.
UPDATE: While writing this issue I have now also encountered the crashing issues when renaming symbols added and used within the same unsaved file. (seems related to #4655 and #2204).
Repro steps
- 
Open a source file which contains a symbol that is defined in another source file. 
  
- 
Add a few lines of code above where that symbol is used. DO NOT SAVE YET 
  
- 
Go to the definition of that symbol in the other file (F12). and use the Rename feature (Ctrl+R+R) to rename that symbol. 
  
- 
The Rename operation overwrites code above where the actual symbols were used and saves the file, corrupting the source code. 
  
Bonus Content
Interestingly, I tried it again with Preview Changes enabled, and the resulting preview window actually shows the corruption:

Repro Solution ZIP
VS2017.15.7.1-BlindRenameOffsetIssue.zip
Expected behavior
Rename feature properly renames usages in open / modified files.
Actual behavior
Rename feature uses old buffer to calculate rename operations, overwriting current buffer and saving the file.
Known workarounds
Only to save all open files before performing any rename operations.
Related information
Provide any related information
- Operating system
- Windows 10, Version 1709 (16299.309)
 
- Branch
- 15.7.1 public release
 
- .NET Runtime, CoreCLR or Mono Version
- .NET Framework 4.7.1
 
- Editing Tools (e.g. Visual Studio Version)
- Visual Studio 15.7.1
 
- Indications of severity
- This issue and the related Rename->VSCrash issues can cause data loss.