C# - User Settings broken

后端 未结 3 1729
情话喂你
情话喂你 2021-01-04 12:53

We had a rare exception occur when reading the standard .Net user settings (this are the ones found in \"project properties\" in VS 2008):

System.Configurati         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 13:27

    The way to programmatically recover is to do what you did manually - delete the user settings file. Then call Settings.Reset. (You could also write a new user settings file with default values instead of deleting it, but if you're using the configuration manager properly that's essentially the same thing.)

    This is a pretty rare occurrence, but it's not totally unheard of. Not only can your program crash while writing the user settings file, the file itself is user-writeable, so other programs the user runs could mess with it.

    To avoid this particular vulnerability, persist user settings in a durable store with transactional integrity, i.e. a database. (You'll still have vulnerabilities, just not this one.) That's a lot of work for what in most cases will be a marginal improvement in reliability. But "in most cases" doesn't mean "in all cases;" yours may warrant it.

提交回复
热议问题