Getting Null Object Ref that I can't pinpoint
Friday, February 28, 2020 at 09:30amcontract 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
Friday, February 28, 2020 at 09:42am{"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
Friday, February 28, 2020 at 10:54amHi Kenage,
After a quick test, the exact same code + a dummy PDF work fine at my side:
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
Reply to: Getting Null Object Ref that I can't pinpoint
Friday, February 28, 2020 at 11:01amI 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
Friday, February 28, 2020 at 12:51pmHi 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
Reply to: Getting Null Object Ref that I can't pinpoint
Friday, February 28, 2020 at 03:05pmPackageId 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
Friday, February 28, 2020 at 04:09pmHi 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