I have a very simple C# console application that copies a specific node from an existing XML file located on my computer to another XML file, also located on my computer. I've hardcoded the paths in an app.config file within the solution.
When I debug my solution (F5) the files get updated appropriately. However, if I run without debugging (Control+F5) or if I build (or publish) to bin/Release or bin/Debug and run the my-console-app.exe the application fails to save any file to disk.
Strangely this app used to work without issue (it was used in conjunction with a .bat file which called it and deployed the updated configuration file to a server). But over the last few weeks I've noticed this console app has seemingly worked less and less over time to the point where to get my update script to run successfully I have to open this console application's solution, press F5, then run my .bat script.
I've used ProcessMonitor by sysinternals to verify that files are being read/written and it says that files are being written to the file paths that I'm specifying, however when I browse to the directory the file doesn't not exist or is not updated.
I'm using VS2010 on a Mac Mini running Windows 7 Ultimate via Bootcamp.
TL;DR; Console app works and updates files appropriately when debugging but not when run without debugging or as a standalone or published .exe from bin/Release, etc.
var devConfig = XDocument.Load(DevConfigPath, LoadOptions.None);
var prodConfig = XDocument.Load(ProductionConfigPath, LoadOptions.None);
var devMethods = devConfig.Descendants("deliveryMethods");
prodConfig.Root.Element("Heg.EA.Delivery").Element("deliveryMethods").ReplaceWith(devMethods);
try
{
Console.WriteLine(String.Format("Dev First Node:{0}", devConfig.Root.Element("ClientDeliveryTest").Element("deliveryMethods").FirstNode.ToString())); // Test Node to ensure file is being read correctly (it is).
Console.WriteLine(String.Format("Production First Node:{0}", prodConfig.Root.Element("Heg.EA.Delivery").Element("deliveryMethods").FirstNode.ToString())); // Test Node to ensure production configuration is updated correctly (it is).
Console.WriteLine("Saving...");
prodConfig.Save(@"C:\ProductionConfig.config"); // FAIL.
prodConfig.Save(@"ProductionConfig.config"); // FAIL.
prodConfig.Save(ProductionConfigPath); // FAIL.
Console.Write("File Saved.");
}
catch (Exception ex) // No exception is ever thrown.
{
Console.Write(String.Format("Error Saving: {0}", ex));
}