Kenage

Getting Null Object Ref that I can't pinpoint

0 votes

contract is a class with accessible properties that have been populated by this point and is a parameter being passed into the call here.

All the text anchors have been verified in the starting doc...

                string sourceFile = pdf.FullName;
                string LenderEmail = "[email protected]";
                bool CoBorrower = false;

                EslClient eslClient = new EslClient(API_KEY, API_URL);

                //Create Base Package
                DocumentPackage documentPackage = 
                    PackageBuilder.NewPackageNamed("Personal Loan Application")
                    .WithSigner
                        (
                        SignerBuilder.NewSignerWithEmail(contract.EmailAddress)
                        .WithFirstName(contract.FirstName)
                        .WithLastName(contract.LastName)
                        .WithCustomId("Borrower")
                        .SigningOrder(1)
                        )
                    .WithSigner
                        (
                        SignerBuilder.NewSignerWithEmail(LenderEmail)
                        .WithCustomId("Lender")
                        .WithFirstName("Test")
                        .WithLastName("Test")
                        .SigningOrder(1)
                        )
                    .WithDocument
                        (
                        DocumentBuilder.NewDocumentNamed("Personal Loan Agreement")
                        .FromFile(sourceFile)
                        .EnableExtraction()
                        .WithId("LoanDocs")
                        .WithSignature
                            (
                            SignatureBuilder.CaptureFor(contract.EmailAddress)
                            .WithPositionAnchor
                                (
                                TextAnchorBuilder.NewTextAnchor("BorrowerSig1")
                                .AtPosition(TextAnchorPosition.TOPRIGHT)
                                .WithSize(300, 40)
                                .WithOffset(-10, -20)
                                )
                            .EnableEnforceCaptureSignature()
                            .WithField
                                (
                                FieldBuilder.SignatureDate()
                                .WithPositionAnchor
                                    (
                                    TextAnchorBuilder.NewTextAnchor("BorrowerSigDate1")
                                    .AtPosition(TextAnchorPosition.TOPLEFT)
                                    .WithSize(100, 20)
                                    )
                                    .WithValue("MM/dd/yyyy HH:mm:ss")
                                )
                            )
                        .WithSignature
                            (
                            SignatureBuilder.CaptureFor(LenderEmail)
                            .WithPositionAnchor
                                (
                                TextAnchorBuilder.NewTextAnchor("LenderSig")
                                .AtPosition(TextAnchorPosition.TOPRIGHT)
                                .WithSize(300, 40)
                                .WithOffset(-10, -20)
                                )
                            .EnableEnforceCaptureSignature()
                            .WithField
                                (
                                FieldBuilder.SignatureDate()
                                .WithPositionAnchor
                                    (
                                    TextAnchorBuilder.NewTextAnchor("LenderSigDate")
                                    .AtPosition(TextAnchorPosition.TOPLEFT)
                                    .WithSize(100, 20)
                                    )
                                    .WithValue("MM/dd/yyyy HH:mm:ss")
                                )
                            )
                        .WithSignature
                            (
                            SignatureBuilder.CaptureFor(contract.EmailAddress)
                            .WithPositionAnchor
                                (
                                TextAnchorBuilder.NewTextAnchor("PromBorrowerSig1")
                                .AtPosition(TextAnchorPosition.TOPRIGHT)
                                .WithSize(300, 40)
                                .WithOffset(-10, -20)
                                )
                            .EnableEnforceCaptureSignature()
                            )
                        .WithSignature
                            (
                            SignatureBuilder.CaptureFor(LenderEmail)
                            .WithPositionAnchor
                                (
                                TextAnchorBuilder.NewTextAnchor("Witness1")
                                .AtPosition(TextAnchorPosition.TOPRIGHT)
                                .WithSize(300, 40)
                                .WithOffset(-10, -20)
                                )
                            .EnableEnforceCaptureSignature()
                            )
                         )
                    .Build();

                PackageID = eslClient.CreatePackage(documentPackage);

I get the Null Ref on the last line, so thinking something isn't defined right in the package, but I can't see it.   I need to add signatures to the package based on logic further down which is why I don't createandsend here.  Is there another method I should be using?


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

{"Object reference not set to an instance of an object."}

Silanis.ESL

 at Silanis.ESL.SDK.ApprovalApiClient.AddApproval(PackageId packageId, String documentId, Approval approval)
   at Silanis.ESL.SDK.ApprovalService.AddApproval(DocumentPackage sdkPackage, String documentId, Signature signature)
   at {Code Line of PackageID above}

Also PackageID is a class property, I realized I missed mentioning that above:

public PackageId PackageID { get; set; }


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

Hi Kenage,

 

After a quick test, the exact same code + a dummy PDF work fine at my side:

2-28-1

Below are some quick self-check steps:

(1)does the code create you a package with PDF uploaded and text anchor detected?

(2)From the error message: " at Silanis.ESL.SDK.ApprovalApiClient.AddApproval(PackageId packageId, String documentId, Approval approval)", it happened when you try to add an approval (signature) to the PDF, and you mentioned "I need to add signatures to the package based on logic further down" which supports the assumption. So could the error occurred after the package has been created and when you manually add signatures? (So might not relate to the snippet you shared, but other codes)

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

I was looking at the next steps after posting the Exception.  The line # is from the snippet above, but it looks like it's just reporting back the last successful line.  The fun of .net debugging.    That aside, here is the next snippet, and it looks like in the AddApproval piece I need the documentID as it was assigned after the package creation, but am running into issues actually finding how to get that...

if (logic...)

{
                    Signature PropWitnessSig =
                                SignatureBuilder.CaptureFor(LenderEmail)
                                        .WithPositionAnchor
                                            (
                                            TextAnchorBuilder.NewTextAnchor("PropAgentCopyWitnessSig1")
                                            .AtPosition(TextAnchorPosition.TOPRIGHT)
                                            .WithSize(300, 40)
                                            .WithOffset(-10, -20)
                                            )
                                        .EnableEnforceCaptureSignature()
                                        .WithField
                                            (
                                            FieldBuilder.SignatureDate()
                                            .WithPositionAnchor
                                                (
                                                TextAnchorBuilder.NewTextAnchor("PropAgentCopyDate1")
                                                .AtPosition(TextAnchorPosition.TOPLEFT)
                                                .WithSize(100, 20)
                                                )
                                                .WithValue("MM/dd/yyyy HH:mm:ss")
                                            )
                                .Build();
                    
                    Signature PropBorrowerSig =
                                SignatureBuilder.CaptureFor(contract.EmailAddress)
                                        .WithPositionAnchor
                                            (
                                            TextAnchorBuilder.NewTextAnchor("PropAgentCopyBorrowerSig1")
                                            .AtPosition(TextAnchorPosition.TOPRIGHT)
                                            .WithSize(300, 40)
                                            .WithOffset(-10, -20)
                                            )
                                        .EnableEnforceCaptureSignature()
                                .Build();
                                 
                    eslClient.ApprovalService.AddApproval(documentPackage, "LoanDocs", PropWitnessSig);
                    eslClient.ApprovalService.AddApproval(documentPackage, "LoanDocs", PropBorrowerSig);
                }

 

So guessing "LoanDocs" is wrong?   Document definition from above:

           .WithDocument
                        (
                        DocumentBuilder.NewDocumentNamed("Personal Loan Agreement")
                        .FromFile(sourceFile)
                        .EnableExtraction()
                        .WithId("LoanDocs")


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

Hi Kenage,

 

I see, from the last function traced from the error message:

"Silanis.ESL.SDK.ApprovalApiClient.AddApproval(PackageId packageId, String documentId, Approval approval)"

It's expecting the PackageId property from the documentPackage object, not sure whether you've manually set package ID for the object after package creation:

            PackageId PackageID = eslClient.CreatePackage(documentPackage);         

           documentPackage.Id = PackageID;

 

Duo


 

 

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

 PackageId PackageID = eslClient.CreatePackage(documentPackage);   happens right after the DocumentPackage and build();

It looks like the issue is in the second parameter of the AddApproval call:  string documentId

What is that value?


Reply to: Getting Null Object Ref that I can't pinpoint

0 votes

Hi Kenage,

 

I meant that if you are passing in the same object "documentPackage", this object may miss the package ID. You can do a quick test by printing out the "documentPackage.Id" before the line invokes ".AddApproval()".

 

On the other hand, the document ID should be fine with hard coded value "LoanDocs".

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off