PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization


#1

Hi,

We’ve implemented a validation to prevent the users from uploading password-protected PDF files using Aspose.Total. This is the code snippet:

if (fileExtension.ToLower() == “.pdf”)
{
PdfFileInfo pdfFile = new PdfFileInfo(filePath);

            if (pdfFile.IsEncrypted)
            {

            }

}

It worked fine when I run the application locally. However, when I deployed a new build on the integration servers, we’re getting this error:

PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization. (File: E:\LSAS_Data\TempResources\637087137530670494.pdf) (Reason: Could not find file ‘E:\LSAS_Data\TempResources\637087137530670494.pdf’.)

Both the file is created and the file location in the server are correct.

The funny thing is that it works fine only the very first time. After that, it throws that error. Why is not working on the servers?
Should we close and dispose the PdfFileInfo instance or include a “using” statement in this scenario? What else is missing?
Please let me know.


#2

@jimmy.rojas

Thank you for contacting support.

You may please try to include the using statement as exception description and mentioned scenario differ because file is accessible on first iteration. Please also ensure using Aspose.PDF for .NET 19.10 in your environment.


#3

Hi,

I’ve tried the 2 options: Closing/disposing the PdfFileInfo instance and including a “using” statement. None alternative worked. I’m getting the same error.
The DDL is updated. What else could it be missing?


#4

@jimmy.rojas

We are unable to reproduce it even in a loop with several iterations. Would you please try to reproduce this in a standalone application as we are of the opinion that problem might not be related with Aspose.PDF for .NET API but probably with file access on the server.


#5

It works fine locally, but it fails the version deployed on the server. Besides, we changed the Server\Users’ Permissions in that folder where is uploaded the files to Full control but it’s still failing.

Same Error: PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization.

Any thoughts?


#6

I was thinking if we should execute this process async because we are open files.


#7

@jimmy.rojas

About the error, it is reproduced only if there is problem with accessing the file. For example, below code works fine:

Document document = new Document(filePath);
PdfFileInfo pdfFile = new PdfFileInfo(document);
var flag = pdfFile.IsEncrypted;

However, almost similar code where source file is not accessed, reproduces same exception:

Document document = new Document(filePath);
PdfFileInfo pdfFile = new PdfFileInfo();
var flag = pdfFile.IsEncrypted;

Therefore, problem is certainly related to file access. About async, you can execute the code asynchronously or in mutli-threaded environment but you can process only one document per thread. In other words, one PDF document should be accessed by one thread at a time.