Edit: I have found the solution. I had thought the error was being generated when attempting to write the files to be compared, in reality it was being generated when I attempted to read the file to be compared. I had a syntax error in the command being called for the comparison executable and that was resulting in the results file not being generated. I was seeing the access violation when I tried to read a non-existent file (yes, I should have been checking for the file existence). I'm having issues getting BC to generate the comparison (for some reason the exact same command works from the command prompt but does not work when ran from C#), but I'll ask that as a separate question if necessary.
I am working on a .net application which is used to compare code changes between builds.
part of the application that I am attempting to add utilizes beyond compare to generate an html comparison of two chunks of code.
In order to do this I am generating files from the code (note that I know the file names will have a conflict issue for multiple users, I will fix this later), then calling the beyond compare executable from command line. I generate the files using the below code:
//write the code to a local disk file
System.IO.File.WriteAllText(@workingFolder + "\\File1.txt", (String)dataRow["OldMethodCode"]);
System.IO.File.WriteAllText(@workingFolder + "\\File2.txt", (String)dataRow["NewMethodCode"]);
The value for workingFolder is this: "C:\inetpub\wwwroot"
The problem that I am running into is that when this code is ran and it attempts to create those files I get the below exception:
[UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot' is denied.] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +216 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1430 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +214
System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost) +187 System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost) +90
_Default.gridView_SelectedIndexChanged(Object _sender, EventArgs e) +1024 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1241
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
I have tried a number of things to resolve this. As with any problem, you can lose track of all your options but here are the ones that I thought had the highest chance of success (but didn't work):
- Add networkService as full permissions to the wwwroot folder
- Add Everyone with full permissions to the wwwroot folder
- Change the application pool managed pipeline mode to classic
- Set the app pool to run with a custom user and give that user full permissions to the folder
- Give just about any other user that seems to be related full privileges to the folder
- Move the folder to another local directory outside of wwwroot and point to that, and try all of the above with that folder.
In all cases, I can't seem to create the file, much less access it to run the comparison.
Does anyone have advice to offer on how to resolve this issue, or an alternative/better way to do the comparison that would not require file creations?
Thanks!