MZ-Tools Articles Series: BUG: EnvDTE.FontsAndColorsItems.Item("Keyword").Background not updated after changing Visual Studio 2012 theme.

One of the things that you need to test in a Visual Studio 2012 add-in or package is that is themed correctly when the VS theme is changed dynamically from Dark to Light or viceversa (through the Tools, Options window). I noticed that sometimes the textboxes that show colorized C# or VB.NET code in my MZ-Tools 7.0 add-in were showing an incorrect background for strings, comments and keywords. I use the RichTextBox control and I get the color information from the EnvDTE.FontsAndColorsItems class, as explained in the article:

HOWTO: Get the text editor font and colors information in a Visual Studio add-in
http://www.mztools.com/articles/2008/MZ2008008.aspx

After reading this thread in the VSX forum, I realized that it happened when switching themes. And today I have filed a bug to Microsoft Connect:

EnvDTE.FontsAndColorsItems.Item(“Keyword”).Background not updated after changing theme
https://connect.microsoft.com/VisualStudio/feedback/details/765401/envdte-fontsandcolorsitems-item-keyword-background-not-updated-after-changing-theme#details

And I have documented it here with the workaround that I am using:

BUG: EnvDTE.FontsAndColorsItems.Item(‘Keyword’).Background not updated after changing Visual Studio 2012 theme
http://www.mztools.com/articles/2012/MZ2012025.aspx

The workaround is not perfect but I also played with the RefreshCache method of the IVsFontAndColorCacheManager interface to no avail.