Exception while converting stream to PdfFileInfo for password protected files

I am using Aspose.pdf version 20.4.0
This dll used for checking whether the PDF is password protected.

While converting the Stream to PdfFileInfo, i am getting below exception

PdfFileInfo is not initialized. Use constructors with parameters or properties for initialization. (Reason: Startxref not found)

I have used below code for checking the protected file and this is running in an API .net core 2.1 version .

     public static bool IsFilePasswordProtected(Stream stream, string extension, out string remarks)
    {
       
        remarks = string.Empty;
        switch (extension)
        {
            case pdf:
                PdfFileInfo pdfFileInfo = new PdfFileInfo(stream);
                bool hasPassword = pdfFileInfo.HasOpenPassword;
                pdfFileInfo.Dispose();
                pdfFileInfo.Close();   
                remarks = hasPassword ? password_protected : "";
                return hasPassword;  
            default:
                return false;
        }
    }

Please let me know if more details required.

@sreeraj_05

Can you please provide the source file that is reproducing the issue on your end and that we may verify on our end to help you further.