exePath是ConfigurationManager.OpenExeConfiguration无效异常 [英] exePath is invalid exception in ConfigurationManager.OpenExeConfiguration
问题描述
我有安装到C windows服务:\Windows\System32。它有一个通常的config文件,其中存储了一些应用程序设置。我还有一个应用程序,写入一些值这个配置。当我运行这个程序,它在这行抛出一个异常
I have a windows service which is installed to C:\Windows\System32. It has a usual .config file, where some app settings are stored. I have another app that writes some values to this config. When i run this app it throws an exception at this line
无功配置= ConfigurationManager.OpenExeConfiguration(serviceExePath);
例外说:发生错误加载配置文件:参数exePath'无效。参数名:exePath 的
当我把我的窗口服务到另一个文件夹一切OK!它是由于一些访问冲突规则或不服这样呢? ?有没有办法使用System32文件夹中为我服务,并打开其配置
When I put my windows service to another folder everything is ok! Is it due to some access violation rules or smth like that? Is there any way to use System32 folder for my service and open its config?
操作系统:Windows 7 64位系统
OS: Windows 7 x64
推荐答案
这是一个文件位置一个糟糕的选择。该目录所属的Windows,它不适合自己的应用程序。首先,你需要管理员权限在该目录中打开文件。你没有得到,如果没有明显的触发UAC提示。
It is a poor choice for a file location. That directory belongs to Windows, it isn't suitable for your own apps. For one, you'll need admin privileges to open files in that directory. You don't get that without a manifest to trigger the UAC prompt.
另一个原因是,该目录是虚拟化的Windows x64版本。 32位应用程序试图访问文件会被重定向到C:\windows\syswow64
For another, that directory is virtualized on the x64 version of Windows. A 32-bit app trying to access files there will be redirected to c:\windows\syswow64.
我本来可以更准确,如果您发布的堆栈跟踪。但是,就是不去做。
I could have been more accurate if you posted the stack trace. But, just don't do it.
这篇关于exePath是ConfigurationManager.OpenExeConfiguration无效异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!