Howto work with Properties.CustomSettings

走远了吗. 提交于 2019-12-24 10:48:23

问题


According to MSDN, one can add customized settings files to ones project for convenient management of groups of settings.

So I created a custom settings by visual designer, set all properties as a User Scoped to be able to save them.I bind some control properties to this customized settings. And change some values mannually through Properties.CustomSettings.MyValue = x;

But when I do Properties.CustomSettings.Default.Save() - nothing happens. The changes are not persisted between application run (I'm aware about Debug version change) .

I searched a file in the directorites that ConfigurationManager gives me (according to this post) but didn't find any track of this CustomSettings.

So, what is the trick with saving this Customized Settings Files and How to save Customized Settings Files?


回答1:


Ok, now I've got a right answer. Everything is OK that this custom settings were created under the dll file.

The problem is with this question Application.UserAppDataPath strange behaviour

If one have AssemblyVersion with automatic Build and Revision Numbers and have AssemblyFileVersion in AseemblyInfo.cs, say, of exe that uses this dll, then Application.UserAppDataPath will throw ArgumentException "Illegal characters in path." Application.UserAppDataPath is used to build path to this config file to save this CustomSettings.

But ApplicationSettingsBase just eats all exceptions that happens inside, so the file is just not saved and nobody could even think about AssemblyFileVersion in AseemblyInfo.cs of exe...

Ohhh my god... 8 hours of fighting with this ... feature...



来源:https://stackoverflow.com/questions/6089468/howto-work-with-properties-customsettings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!