Hi Guys,
I am facing interesting situation when I am trying to run my tests in parallel using GroupDocs.Comparison for comparing files.
If I am running code below within my tests (that are running in parallel)
public void IsSame(string sourceFile, string fileToCompare)
{
using (Comparer comparer = new Comparer(sourceFile))
{
comparer.Add(fileToCompare);
comparer.Compare(
"Report.pdf",
new CompareOptions
{
DetalisationLevel = DetalisationLevel.High,
DetectStyleChanges = true,
});
}
}
I am getting following exception:
\u0006 : Object reference not set to an instance of an object… Comparison cannot create result document.
Stack trace
[at \u0005 .SaveDocument(Stream \u0002, Document \u0003, Document \u0005, SaveOptions \u0008)]
[at GroupDocs.Comparison.Comparer.\u0002(Stream \u0002, SaveOptions \u0003)]
GroupDocs.Comparison.Comparer.%2Fu0002&version=GBmain&_a=contents&line=1&lineEnd=2&lineStartColumn=1&lineEndColumn=1&lineStyle=plain)
at GroupDocs.Comparison.Comparer.Compare(Stream document, SaveOptions saveOptions, CompareOptions compareOptions)
at GroupDocs.Comparison.Comparer.Compare(String filePath, CompareOptions compareOptions)
However if I am running code below (with lock) in parallel it does work for me without exceptions:
private static readonly object lockObj = new();
public void IsSame(string sourceFile, string fileToCompare)
{
using (Comparer comparer = new Comparer(sourceFile))
{
comparer.Add(fileToCompare);
lock (lockObj)
{
comparer.Compare(
"Report.pdf",
new CompareOptions
{
DetalisationLevel = DetalisationLevel.High,
DetectStyleChanges = true,
});
}
}
}
So I guess question is if GroupDocs.Comparsion is thread safe and should allow me to run comparison in parallel, if yes, maybe you could suggest why it does not work for me, please?
Thanks in advance.