简体   繁体   中英

Getting wrong path of xml file after installing windows service

I have written the below code to load xml file.

  XDocument doc = XDocument.Load(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Configurations.xml");

It is working fine if I am debugging the code using Visual Studio, however after installation it is finding the file at this location

Could not find file 'C:\\Windows\\system32\\Configurations.xml'.

How to resolve the same?

Services are started with Service Control Manager so the directory is %WinDir%\\System32 or %WinDir%\\SysWOW64 .

The most appropriate directory path would be AppDomainSetup.ApplicationBase

Gets or sets the name of the directory containing the application.

You can access this information for the current domain with AppDomain.CurrentDomain.SetupInformation.ApplicationBase expression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM