C# 安装windows服务后获取错误的xml文件路径
我已经编写了下面的代码来加载xml文件C# 安装windows服务后获取错误的xml文件路径,c#,windows-services,C#,Windows Services,我已经编写了下面的代码来加载xml文件 XDocument doc = XDocument.Load(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Configurations.xml"); 如果我使用VisualStudio调试代码,它可以正常工作,但是在安装之后,它会在这个位置找到文件 找不到文件“C:\Windows\system32\Configurations.
XDocument doc = XDocument.Load(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Configurations.xml");
如果我使用VisualStudio调试代码,它可以正常工作,但是在安装之后,它会在这个位置找到文件
找不到文件“C:\Windows\system32\Configurations.xml”。
如何解决相同问题?服务是以启动的,因此目录是%WinDir%\System32
或%WinDir%\SysWOW64
最合适的目录路径是
获取或设置包含应用程序的目录的名称
您可以使用AppDomain.CurrentDomain.SetupInformation.ApplicationBase
表达式访问当前域的此信息