[GH-ISSUE #30] AssertThat throws error if Attribute or Feature deos not exist #25

Closed
opened 2026-02-26 01:35:48 +03:00 by kerem · 2 comments
Owner

Originally created by @MikeWilliams-UK on GitHub (Apr 17, 2023).
Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/30

In a .Net Framework (4.6.2) application.

If you have a licence which has been generated with an attribue of "Random1" and when you validate it you try to get an attribute of "Random2" you get a System.NullReferenceException when using .AssertThat(lic => lic.AdditionalAttributes.Get("Random2")

Same happens if you specify a feature which does not exist in the licence.

I would expect both of these to gracefully fail validation with a message similar to "Attribute 'Random2' not present in the licence."

Originally created by @MikeWilliams-UK on GitHub (Apr 17, 2023). Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/30 In a .Net Framework (4.6.2) application. If you have a licence which has been generated with an attribue of "Random1" and when you validate it you try to get an attribute of "Random2" you get a System.NullReferenceException when using .AssertThat(lic => lic.AdditionalAttributes.Get("Random2") Same happens if you specify a feature which does not exist in the licence. I would expect both of these to gracefully fail validation with a message similar to "Attribute 'Random2' not present in the licence."
kerem closed this issue 2026-02-26 01:35:48 +03:00
Author
Owner

@SamKr commented on GitHub (Sep 30, 2024):

If anyone comes across this, the correct way to implement this can be found in @junian's tests projects for Standard.Licensing.

Example:

var validationFailures = license.Validate()
    .ExpirationDate(systemDateTime: DateTime.Now)
    .When(lic => lic.Type == LicenseType.Trial)
    .And()
    .Signature(EncryptedPublicKey)
    .And()
    .AssertThat(lic => lic.ProductFeatures.Contains("Sales Module"), new GeneralValidationFailure { Message = "Sales Module not licensed!" })
    .AssertValidLicense();

You can change Sales Module into anything you want, and it'll trigger the corresponding failure if it's not present in the license.

<!-- gh-comment-id:2383081227 --> @SamKr commented on GitHub (Sep 30, 2024): If anyone comes across this, the correct way to implement this can be found in @junian's [tests projects](https://github.com/junian/Standard.Licensing/blob/master/src/Standard.Licensing.Tests/LicenseValidationTests.cs) for Standard.Licensing. Example: ```csharp var validationFailures = license.Validate() .ExpirationDate(systemDateTime: DateTime.Now) .When(lic => lic.Type == LicenseType.Trial) .And() .Signature(EncryptedPublicKey) .And() .AssertThat(lic => lic.ProductFeatures.Contains("Sales Module"), new GeneralValidationFailure { Message = "Sales Module not licensed!" }) .AssertValidLicense(); ``` You can change `Sales Module` into anything you want, and it'll trigger the corresponding failure if it's not present in the license.
Author
Owner

@junian commented on GitHub (Oct 2, 2024):

Thanks for pointing that @SamKr

<!-- gh-comment-id:2389139504 --> @junian commented on GitHub (Oct 2, 2024): Thanks for pointing that @SamKr
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Standard.Licensing#25
No description provided.