PowerShell Get PDF Page Count

Hi since the last update the folowing script in PowerShell raise an error. The script did not change at all, so something is wrong with the current version.

current version: 22.2.0
last version: 21.6.0

Please try the script below. Before trying please change path of pdf file and aspose.pdf.dll

Script:

$inputFilePath = “D:\weg\200701124019.00108075.pdf”
$asposeDllPath = “D:\LCS\Winyard\Testprojekte\AsposeCreatePDFFile\AsposeCreatePDFFile\bin\Debug”

function Test
{
[CmdletBinding()]
[OutputType([boolean])]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Filename
)

[Aspose.PDF.Document] $PDFDoc = New-Object Aspose.PDF.Document($inputFilePath)

Write-Host ("Filename: "+$Filename)
Write-Host ($PDFDoc.Pages.count)

Return $true
}

$ergebnis = Test -Filename $inputFilePath
$ergebnis.ToString()

@schlumpfger

Can you please also share the error text that you are receiving while getting the PDF Page Count in PowerShell? We tested your script in our environment and faced below error. Did you also face the same?

The following exception occurred while retrieving member "Pages": "Type handle 'Aspose.Pdf.Document' and method handle with declaring type 
'#=zaopCQf_aFeotNcDeg5nzt76fjdrghMD9c2$ST$kEad7z+#=znKnBr4w=' are incompatible. Get RuntimeMethodHandle and declaring RuntimeTypeHandle off the same MethodBase."

The error is very similar to yours.

Ausnahme beim Abrufen des Elements “Pages”: “Typhandle “Aspose.Pdf.Document” und Methodenhandle mit dem deklarierenden Typ “#=zb5hL1HbhDaWqXh1rUAgi$38=” sind nicht
kompatibel. Entfernen Sie RuntimeMethodHandle und den deklarierenden RuntimeTypeHandle aus derselben MethodBase.”
In C:\Users\tietze.LCS\Documents\Unbenannt1.ps1:40 Zeichen:2

  • Write-Host ($PDFDoc.Pages.count)
  •  + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
     + FullyQualifiedErrorId : CatchFromBaseGetMember

@schlumpfger

An issue as PDFNET-51415 has been logged in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-51415) have been fixed in Aspose.PDF for .NET 22.12.