“配置系统初始化失败”从 Settings.settings 获取值时

发布于 2024-10-30 15:52:08 字数 628 浏览 3 评论 0原文

对这个问题太沮丧了... :-(

Winforms、C# 2.0、VS 2010

在开发时,我只是尝试访问 Settings.setting 文件中的设置值。例如:

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

正如预期的那样,但

在任何其他计算机上部署我的 .exe 文件时,我收到一个配置系统无法初始化异常,提示:无法找到路径 C 的一部分。 :\Documents and Settings\...\user.config

在我的 Settings.settings 文件中,我有一些应用程序范围的字符串和一个用户范围的 WebService URL,因为 URL 值我需要它作为用户范围。可能会在运行时更改

:我刚刚创建了一个测试应用程序,它仅引发一个包含一个应用程序范围的字符串值和一个用户范围的字符串值的 MessageBox,它无需保存设置即可工作。 >Settings.Default.Save() 也没有其他一些“额外”操作...这让我发疯:(

任何帮助将非常感激。

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 simply 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-11-06 15:52:08

在另一台计算机上,如果您看到名为 YourApplicationName.vshost.exe 和 YourApplicationName.vshost.exe.config 的文件,请删除它们并查看错误是否仍然存在。

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.

荒芜了季节 2024-11-06 15:52:08

我知道这已经晚了两年了,但是嘿,这是给谷歌员工的。

当我在 C# 中使用资源文件和内置应用程序设置(以 .NET 4.0 为目标,在 Windows 7 上使用 Visual Studio 2010)时,更改命名空间后,我遇到了针对不同问题的相同错误文本。

基本上,命名空间被搞乱了,配置文件不匹配。我最终得到了相同的错误文本。

1) 确保 Resources.Designer.cs 中设置资源管理器的行正确。例如: global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("YOUR_NAMESPACE_NAME.Properties.Resources", typeof(Resources).Assembly); 我的命名空间正在使用被搞乱了。确保引号之间的文本准确。

2) 删除user.config文件。它不一定位于您的项目中。我在 C:/users/myusername/AppData/Local/CompanyName/Project_name_with_a_random_string/1.0.0.0/user.config 找到了我的,

它可以解决我的问题。对于您的,我建议您查看上面 2) 中指示的文件夹。如果您没有 user.config,则需要强制应用程序创建一个。当我调用 Properties.Settings.Default.Save(); 时,就会发生这种情况,仅在表单 init 上调用 save 可能不会造成伤害。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文