We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception” Object reference not set to an instance of an object” add digital signature in PDF using Aspose.PDF for .NET

i got an error. add digital signature in PDF and deploy to k8s.

Source code:

using (Document document = new Document(finalPDFFilePath))
        {
            using (PdfFileSignature signature = new PdfFileSignature(document))
            {
                PKCS7 pkcs = new PKCS7(certFilePath, certPin); // Use PKCS7/PKCS7Detached objects
                signature.Sign(1, "", "", "", false, new System.Drawing.Rectangle(0, 0, 200, 100), pkcs);
                // Save output PDF file
                signature.Save(signedPdfPath);
            }
        }

install package is:
Aspose.PDF 22.7.0
Aspose.Words 22.8.0
SkiaSharp.NativeAssets.Linux.NoDependencies 2.88.0

error is:

System.NullReferenceException: Object reference not set to an instance of an object.
   at #=z$HFtu4h7MeeNpCkReDTZDfwCVDVe.#=zetu2Mzs=(#=znfCmefDmMB013VcLwGnRrXdz4S_2 #=ziocaaOgdqBXi)
   at #=zISc35fZbrRlU4tul9$bfVwg=.#=zd8Wstn4=(#=znfCmefDmMB013VcLwGnRrXdz4S_2 #=ziocaaOgdqBXi)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=z7URyNe7NvDbxFpg5H7VVQC95y3RdEE$dPuLM76fwYkyf(Object #=zm2ekIcs=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=ziHMnAyNxv8VTxDNH4DTBhLY=(MethodBase #=zm2ekIcs=, Boolean #=z4CS35XU=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=zdSwThCHvamFUkdivJNYAbiFZLjHvKxNbbQ==(#=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M= #=zm2ekIcs=, #=qb1BnzI_hXJAzEwlEGsTlHP3G6ho40kEVQLJRwo5CKQA= #=z4CS35XU=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZB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$E1Ggu3jILlnTKDgY=(Object #=zm2ekIcs=, UInt32 #=z4CS35XU=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=z78MYQurxd9zZsKNK7XxjtEa_Hl41iBVGINdbMiY=(Boolean #=zm2ekIcs=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=z78MYQurxd9zZsKNK7XxjtEa_Hl41iBVGINdbMiY=(Boolean #=zm2ekIcs=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=zHw1u0kdRJb8my$VU2907Od6Pa80L(Object[] #=zm2ekIcs=, Type[] #=z4CS35XU=, Type[] #=zpNB6c8g=, Object[] #=znZ93BY8=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=zIeN4oZuEBWy3dpLS2FwWmyIttKUw9HXtKHUlhV8=(Stream #=zm2ekIcs=, String #=z4CS35XU=, Object[] #=zpNB6c8g=)
   at #=qK5IoDj6SxwEpSQAma5mBiRzUkmKT9huStZ_ZBu$aH2M=.#=zC3JySfpmYg$FGfT_aFLLNpH44RA80kdcxKzipVs=(Stream #=zm2ekIcs=, String #=z4CS35XU=, Object[] #=zpNB6c8g=)
   at Aspose.Pdf.Document.#=zzVLj$_JhiwK4(SaveOptions #=z5LvX9e7QCw5b)
   at Aspose.Pdf.Facades.PdfFileSignature.#=zHjx5ttlMK8u4(Stream #=zC9$QN2o3BucB, Stream #=zqMZHDqiBx7YG, String #=zUY7U7iU=)
   at Aspose.Pdf.Facades.PdfFileSignature.Save(Stream outputStream)
   at Aspose.Pdf.Facades.PdfFileSignature.Save(String outputFile)
   at SelfSignatureApi.Controllers.SignAsposeWordsController.Get(String empId, String finalPDFFilePath, String s0101, Int32 v3201) in /src/SelfSignatureApi/Controllers/SignAsposeWordsController.cs:line 69
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS

Accept: /
Connection: keep-alive
Host: 192.168.4.12:30038
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7
Referer: http://192.168.4.12:30038/swagger/index.html

@weiyilai

Could you please share your input PDF and certificate files along with certificate password here for testing? We will investigate the issue and provide you more information on it.