The process cannot access the file because it is used by another process - prod

The process cannot access the file because it is used by another process.
If the image is open I get the above error.

Here is my code:

PdfContentEditor pdfContentEditor = new PdfContentEditor(pdfDocument);
pdfContentEditor.ReplaceImage(1, 1, AppSettings.GetValue(AppSettings.img) + @"\img.jpg");

using (MemoryStream ms = new MemoryStream())
{
pdfContentEditor.Save(ms);
result = ms.ToArray();
}
I try to add pdfContentEditor.Close, but it didn’t help.

I need a solution for production

I would appreciate your help

@osnatMusic

We suggest you please try the latest version of Aspose.PDF for .NET 22.12 and let us know how it goes on your side. Hope this helps you.

If you still face problem, please share some detail of your use case along with input PDF and image file here for testing. We will investigate the issue and provide you more information on it.

I purchased the license a few months ago. What do you mean ?

@osnatMusic

If you open the image file in image viewer and try to access same file by another process, you will get the same exception.

Could you please share some detail why you want to open the image and access it via Aspose.PDF?

Please also share your input PDF and image file here for testing. We will investigate this issue and provide you more information on it.

Is it possible to replace image without going to path routing, but with a string or base64?

@osnatMusic

We suggest you please read the following article and use following code example to achieve your requirement. Hope this helps you.
Replace Image in Existing PDF File

var bytes = Convert.FromBase64String("....");
var contents = new MemoryStream(bytes);

// Open document
Document pdfDocument = new Document("input.pdf");
// Replace a particular image
pdfDocument.Pages[1].Resources.Images.Replace(1, contents);
// Save updated PDF file
pdfDocument.Save("output.pdf");