Free Support Forum -

Permission Denied error when using C# Comparer.ConvertToImages method


Hello there,

I’m trying to export images for the documents being compared, and have encountered what appears to be a problem with the Comparer.ConvertToImages method.

I do the comparison

Comparer comparer = new Comparer();
var comparisonResults = comparer.Compare(stream1, stream2, new ComparisonSettings());

I build a temp path like so.

var outputDirectoryName = $"{DateTimeOffset.Now.ToUnixTimeMilliseconds()}-{Guid.NewGuid()}";
var tempDirectoryPath = Path.Combine(Path.GetTempPath(), outputDirectoryName);

then, i create the directory


this line of code works


but this line does not,

var pageImages = comparer.ConvertToImages(tempDirectoryPath);

I get an error message like this:

Access to the path 'C:\\Users\\<usernamehere>\\AppData\\Local\\Temp\n2694120781-7fbcbed0-1cb6-4e67-88f2-1e17a1843c2f' is denied.

But it’s not, because if i look in the directory, i can see images the SaveImages method was able to create there.

I’ve tried commenting out the SaveImages method call, specifying a directory and giving that directory read/write access to all users, neither worked.

Any advice would be greatly appreciated.




Another discovery on this. the path i create is something like:


But the error message says

Access to the path ‘C:\Users\(usernamehere)\AppData\Local\Temp\n2696277407-9ec02f51-9ba1-4537-aa2b-526c17f8dfbc’ is denied.

I don’t know what’s happening, but the first 3 characters of the folder name are being converted to an random letter, and there’s only one \ instead of two \ like everywhere else in the path.

should be: \\1562696277407-9ec02f51-9ba1-4537-aa2b-526c17f8dfbc
what shows up in error: \n2696277407-9ec02f51-9ba1-4537-aa2b-526c17f8dfbc

hope this helps



This issue is reproduced at our end. Hence, it has been logged in our internal issue tracking system with ID : COMPARISONNET-1969. We are now further investigating it. As we have any update, you’ll be notified.



You are facing this issue because you are passing folder path to ConvertToImages as follows:

You have to pass file path to it.
List<PageImage> pageImages = comparison.ConvertToImages(@"D:\result.pdf");
Now you will have/get images in pageImages list and those could be saved wherever you want.