3

I want to create a situation where .Net throws this exception:

InvalidOperationException: Cannot load Counter Name data because an invalid index '' was read from the registry.

For example, in this question Cannot load Counter Name data because an invalid index -Exception

The reason I want to do this is because a small but significant percentage of the users of my application encounter this and I want to detect that situation and show a dialog that can help users fix it by running lodctr. (Unfortunately, simply fixing the calling code isn't an option as the exception is thrown in a third party library) To validate this process, I will need to be able to encounter the problem.

It should go without saying, but I would like to corrupt the performance counter registry in a way that my computer remains usable and is easily recoverable by using lodctr. I don't want to brick my machine.

Community
  • 1
  • 1
Zachary Burns
  • 453
  • 2
  • 9
  • 1
    Does the explanation of the error's cause from [Pablissimo](http://stackoverflow.com/a/18467730/2592875) in your link not work for you? – TnTinMn Apr 19 '17 at 15:01
  • Somehow I missed that. I will try adding some blank lines, after figuring out whether where the blank lines are matters. – Zachary Burns Apr 19 '17 at 15:20
  • @TnTinMn Attempting to edit this value (even making no changes) results in RegEdit complaining with 2 dialogs "Data of type REG_MULTI_SZ cannot contain empty strings. Registry Editor will remove all empty strings found." then "Cannot edit Counter: Error writing the value's new contents." – Zachary Burns May 16 '17 at 20:43

1 Answers1

0

I have had to solve the same problem for different reasons. Pablissimo's method, and other like it, never worked for me. Here was my method, which has always left my machine entirely usable.

On the machine where you want to corrupt the counters, issue your recovery command: lodctr /r or whatever.

Once it begins rebuilding the counters, wait a few seconds, then abruptly kill the power to the machine before it can finish. This is a hard kill. Just, BAM! No power.

Timing is not a huge requirement, but is mildly important. If you're too early, it will fail to corrupt the performance counters. If you're too late, it will successfully complete the rebuild.

Travis
  • 1,044
  • 1
  • 17
  • 36
  • 2
    This may be correct, but I'm hesitant to endorse it by accepting it as an answer. I'm hesitant to even try it myself. – Zachary Burns Aug 09 '18 at 14:44
  • Fair enough. In my case, we had no special counters that needed to hang around, and the cost of ruining it was a simple re-image of the machine, which was acceptable for the units affected. That said, I've never had it do any harm (beyond corrupting the counters) over hundreds of executions. I did mine in Windows 10. – Travis Aug 13 '18 at 21:08