为什么我的 DLL.config 文件无法在某些计算机上加载
我有一个用 C# 编写的 Outlook 加载项 MyAddin.dll,它有一个配置文件 MyAddin.dll.config。两者都存储在同一目录中。它们被放置在那里并由安装人员安装。在大多数安装中,查找和读取配置文件没有问题。但是,在一些安装中(完全相同的版本、安装等),.config 永远不会打开。
配置文件内容如下所示...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
...
</configSections>
<system.diagnostics>
<switches>
<add name="MySwitch" value="4" />
</switches>
</system.diagnostics>
</configuration>
我通过在我的一个类中的外接程序中调用隐式加载此配置文件...
internal static TraceSwitch myTraceSwitch =
new TraceSwitch("MySwitch", "My Trace Level Switch");
就像我说的,这适用于许多安装,但不适用于少数安装。我已经运行 PROCMON 来监视配置文件上的文件事件。在加载文件的系统上,PROCMON 在跟踪中显示它。在不加载的系统上,PROCMON 不会显示配置文件。
为什么我的 C# 编译的应用程序扩展 (DLL) 可以在一个实例中正确加载,但甚至不会尝试在另一个实例中加载配置文件?或者,您能否提供诊断此问题的建议?在哪里查看等。
更多信息:该插件编译为“任何 CPU”,安装在 Windows 7 x64 上。已安装 32 位版本的 Office 2010 (Outlook)。所有这些参数对于工作版本和不打开配置文件的版本都适用。
更多信息(2/21/2012): 该插件是在发布模式下构建的。在VS2008项目属性>构建下,选中“定义TRACE常量”。该解决方案面向 .NET 3.5 Framework。该行为似乎是失败的计算机上的 System.Diagnostics.TraceSwitch 实现与其他计算机上的不同。我使用进程资源管理器将故障机器与工作机器进行比较,区别主要在于故障机器大部分具有预编译程序集,而工作机器则没有。这应该重要吗?
I have an Outlook Add-in written in C#, MyAddin.dll, that has a configuration file MyAddin.dll.config. Both are stored in the same directory. They are placed there and installed by an installer. On most installations, there is no problem with finding and reading the config file. But, on a few installations (exact same version, install, etc.), the .config is never opened.
The config file contents looks like this...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
...
</configSections>
<system.diagnostics>
<switches>
<add name="MySwitch" value="4" />
</switches>
</system.diagnostics>
</configuration>
I implicitly load this config file with a call in my addin in one of my classes...
internal static TraceSwitch myTraceSwitch =
new TraceSwitch("MySwitch", "My Trace Level Switch");
Like I said, this works on many installations, but not on a few. I have run PROCMON to watch for the file events on the config file. On systems where the file loads, PROCMON shows it in the trace. On systems where it does not load, PROCMON shows no mention of the config file.
Why would my C# compiled application extension (DLL) correctly load in one instance, but won't even try to load the config file in another? Or, could you please provide suggestions for diagnosing this? where to look, etc.
More info: The Add-in is compiled "Any CPU", it is installed on Windows 7 x64. The 32-bit version of Office 2010 (Outlook) is installed. All of these parameters are true for both the working versions and the one that does not open the config file.
More info(2/21/2012): The addin is built in the release mode. Under VS2008 Project Properties>Build, the "Define TRACE constant" is checked. The solution targets the .NET 3.5 Framework. The behavior appears to be that the System.Diagnostics.TraceSwitch implementation on the machines where this fails is different than on other machines. I've used process explorer to compare a failing machine to a working one, and the difference is mainly that the failing machine has mostly precompiled assemblies while the work one does not. Should that matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否更明确地告诉您的代码使用 ConfigurationChannelFactory 查找配置信息?
http://msdn.microsoft.com/en -us/library/dd575430%28v=VS.100%29.aspx
Could you more explicitly tell your code to find configuration information with a ConfigurationChannelFactory?
http://msdn.microsoft.com/en-us/library/dd575430%28v=VS.100%29.aspx