如何调试.NET 中的配置文件?

发布于 2024-09-07 06:34:44 字数 1163 浏览 11 评论 0原文

我有一个 Visual Studio 项目最近开始抛出 ConfigurationErrorsException,但我不知道它来自哪里。我到处寻找,找不到任何类似错误的东西,而且当我的任何队友在他们的电脑上运行该项目时,他们都没有出现这个错误。

有人对如何调试配置文件的加载和解析有任何具体建议吗?由于 ConfigurationManager 是框架代码,我没有源代码,无法使用 Visual Studio 调试器进入它,所以我在黑暗中寻找。

我非常希望至少能够看到加载了哪些文件,检索了哪些部分、键等,以及加载后续配置文件时覆盖了哪些值。

仅供参考,该项目是使用 .NET 3.5 在 Visual Studio 2008 中编辑的 InfoPath 表单项目。首次加载表单时发生异常;一个方法尝试从配置文件获取 Web 服务 URL:

_clmWebSrvc.Url = System.Configuration.ConfigurationSettings.AppSettings["CLMUtilityWebServiceUrl"];

该方法失败(仅对我而言!):

System.Configuration.ConfigurationErrorsException
The configuration section 'connectionStrings' has an unexpected declaration.
   at System.Configuration.ConfigurationManager.get_ConnectionStrings()

我在任何地方都找不到 connectionStrings 部分; machine.config 中曾经有一个默认配置,但我很久以前就删除了它,因为它导致我维护的一些 Web 应用程序发生冲突。 Infopath.exe.config 中没有任何此类内容,继承链中的任何其他配置文件中也没有此类内容。我停止了在本地 IIS 中运行的单独网站。我重新安装了VS2008、InfoPath,清除了InfoPath FormCache,重命名了我的用户配置文件并重新启动了我的电脑,以完全不同的用户身份登录,但都没有效果。

正如您所看到的,这些都是笨拙且绝望的尝试,试图找出哪些配置文件影响应用程序。我真正想要的是一个能够准确显示正在加载的内容的实用程序。有这样的动物吗?

谢谢!

I've got a Visual Studio project that recently started throwing a ConfigurationErrorsException, and I can't figure out where it's coming from. I've hunted high and low, can't find anything like the error, and it doesn't appear for any of my teammates when they run the project on their PCs.

Does anyone have any specific advice on how to debug the loading and parsing of config files? Since the ConfigurationManager is framework code, I don't have the source and can't step into it with the Visual Studio debugger, so I'm hunting around in the dark.

I'd dearly love to be able at least to see which files are loaded, what sections, keys, etc. are retrieved, and what values are overridden when subsequent config files load.

Just FYI, the project is an InfoPath form project edited in Visual Studio 2008, using .NET 3.5. The exception happens when the form is first loading; a method tries to get a Web Service URL from the config file:

_clmWebSrvc.Url = System.Configuration.ConfigurationSettings.AppSettings["CLMUtilityWebServiceUrl"];

which fails (only for me!) with:

System.Configuration.ConfigurationErrorsException
The configuration section 'connectionStrings' has an unexpected declaration.
   at System.Configuration.ConfigurationManager.get_ConnectionStrings()

I can't find a connectionStrings section anywhere; there used to be a default one in machine.config, but I removed it long ago as it caused conflicts in some of the web apps I maintain. There's nothing of the sort in Infopath.exe.config, nor in any other config file that would be in the inheritance chain. I stopped the separate web site I had running in local IIS. I reinstalled VS2008, InfoPath, cleared the InfoPath FormCache, renamed my user profile and restarted my PC, logged in as a totally different user, all to no effect.

As you can see, these are all clumsy, desperate attempts to find out what config files affect the app. What I really want is a utility that will show me exactly what's being loaded. Is there any such animal?

Thanks!

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

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

发布评论

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

评论(3

请别遗忘我 2024-09-14 06:34:44

查看 System Internals (MSFT) 中的进程监视器。您应该在进程中过滤它,这将允许您查看它正在尝试打开哪些文件以及它正在查找的位置。

然后,您还可以使用 Red Gate .NET Reflector,这将让您迈出一步到 .NET 类(例如 ConfigurationManager)中,以便您可以直接调试到引发异常的实际源。

Check out Process Monitor from System Internals (MSFT). You should filter it on your process, which will allow you to see what files it is trying to open, and where it is looking.

Then, you can also employ Red Gate .NET Reflector, which will let you step into .NET classes such as ConfigurationManager so that you can debug right down to the actual source of the exception being thrown.

舟遥客 2024-09-14 06:34:44

一个响应但可能无法回答您的问题是下载 .NET 的符号文件(当然,其中包括您的配置程序集)。

我不记得 2008 年的调试选项中是否预先填写了它,但这里有一篇 Hanselman 帖子,以防万一:
可供查看的 .NET Framework 库源代码

A response but maybe not answer to your problem is to download the symbol files for .NET (which, of course, includes your Configuration assembly).

I can't remember if it's pre-filled in the Debug options in 2008, but here's a Hanselman post just in case:
.NET Framework Library Source Code available for viewing

赠我空喜 2024-09-14 06:34:44

如果缺少 connectionStrings 部分,则可能会引发此错误。

您的错误是从 machine.config 中删除了 connectionStrings 部分 - .NET Framework 的某些部分要求存在此部分。

您不应手动修改 machine.config。相反,任何有问题的应用程序都应该使用

<connectionStrings>
    <clear/>
</connectionStrings>

它将清除 machine.config 中定义的所有连接字符串。

This error can be thrown if the connectionStrings section is missing.

Your mistake was removing the connectionStrings section from machine.config - some parts of the .NET Framework require this section to be present.

You should not manually modify machine.config. Instead, any apps that are having problems should use

<connectionStrings>
    <clear/>
</connectionStrings>

which will clear any connection strings that have been defined in machine.config.

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