How to solve “Cannot load Counter Name data because an invalid index ” was read from the registry.” error

Getting an error “Cannot load Counter Name data because an invalid index ” was read from the registry.” when the System.Diagnostics.PerformanceCounterCategory API is used, means that something went wrong with the Performance counter registry settings.

In order to fix the wrong behavior you need to restore the Performance counter registry settings, using the following command:

lodctr /R

Additional information about the lodctr command line tool can be found here.