It seems that we found a bug on VSTO for Word.
When using the AutoCorrect.Entries.Add method to add new entries, those are just added in memory and are committed to the dictionary files only when Word gets closed or disposed.
The problem is that when adding an entry or more to multiple languages in the same instance of Word, only the last language gets committed to the dictionary files.
This is an example of the code:
using var wordApplication = new ApplicationClass();
foreach (var languageId in languageIds)
{
var wordDoc = wordApplication.Documents.Add();
wordDoc.Range().InsertAfter("Text");
wordDoc.Range().LanguageID = languageId;
foreach (var entry in addedEntries)
{
wordApplication.AutoCorrect.Entries.Add(entry.Item1, entry.Item2);
}
wordDoc.Close(false);
}
We already tried also this simplified version but the result is the same:
using var wordApplication = new ApplicationClass();
foreach (var languageId in languageIds)
{
wordApplication.ActiveDocument.Content.LanguageID = languageId
foreach (var entry in addedEntries)
{
wordApplication.AutoCorrect.Entries.Add(entry.Item1, entry.Item2);
}
}
While debugging both code examples we can see that word application.AutoCorrect.Entries contain the new entries for each of the languages we are cycling but when Word gets closed at the end of the cycle only the last language gets committed to the disk, the other dictionaries are not modified and the entries get lost.
By physically opening Word on the machine we can confirm that only the last language contains the autocorrect entries and the other doesn't.