开发者

"Configuration system failed to initialize" when getting values from Settings.settings

Too much frustrated with this problem... :-(

Winforms, C# 2.0, VS 2010

While developing, I just try to access to a setting value in Settings.setting file. For example:

string foo = MyProject.Properties.Settings.Default.InstallerLogFile_Path

As expected, it works.

But while deploying my .exe file at any other machine, I'm getting an Configuration system failed to initialize exception. Inner exception says: Could not find a part of the path C:\Documents and Settings\...\user.config.

In my Settings.settings file I have a few application-scoped strings and one user-scoped WebService URL. I need it as user-scoped since URL value may change at runtime.

EDIT: I have just created a test application that simpl开发者_开发百科y raises a MessageBox with one application scoped string value and one user scoped string value. It works with no need of saving the settings Settings.Default.Save() nor some other "extra" actions... this is driving me crazy :(

Any help will be very much appreciated.


On your other machine if you see a file called YourApplicationName.vshost.exe and YourApplicationName.vshost.exe.config delete them and see if the error still persists.


I know this is two years late, but hey, it's for googlers.

I had this same error text for a different problem after changing namespaces when I was using resource files and built-in application settings in C#, targeting .NET 4.0, with Visual Studio 2010 on Windows 7.

Basically, the namespace was messed up and the config file didn't match. I ended up with the same error text.

1) Ensure in Resources.Designer.cs that the line that sets your Resource Manager is correct. For example: global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("YOUR_NAMESPACE_NAME.Properties.Resources", typeof(Resources).Assembly); My namespace that it was using was messed up. Make sure the text between the quotes is accurate.

2) Delete the user.config file. It's not neccesarily located with your project. I found mine at C:/users/myusername/AppData/Local/CompanyName/Project_name_with_a_random_string/1.0.0.0/user.config

That worked for my problem. For yours, I would suggest you look in the folder indicated in 2) above. If you don't have a user.config there, you need to force the application to create one. This happens for me when I call Properties.Settings.Default.Save(); Probably won't hurt just to call save on form init.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜