1

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));
}
4

1 回答 1

0

找到了解决方案。我将我的解决方案上传到我的工作存储库并让我的老板检查它。他能够打开它、构建它、调试它,并从 bin/Release 运行 exe。然而,当他运行 exe 时,Avast 弹出一条友好的消息,拒绝他访问,他对此进行了补救,程序继续执行。

我也有 Avast。它从未提示我允许/禁止我的应用程序执行或写入磁盘。但是我去了 avast 选项并禁用了 AutoSandbox 功能,一切正常。

TL;博士; 防病毒设置阻止我的控制台应用程序写入磁盘并且没有提示我。

于 2012-06-21T00:05:01.200 回答