[GH-ISSUE #12] validationFailures.ToList() not working #10

Open
opened 2026-02-26 01:35:46 +03:00 by kerem · 4 comments
Owner

Originally created by @Manfrons on GitHub (Jan 23, 2020).
Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/12

It seems that after iterate over the failures collection, calling ToList() or ToArray() doesn't populate it again.
You can test with this code.
I've generated an xml license file (copy/paste from main page), changed the expiration date inside the xml file and called the verification.
Any returns true, but the foreach is skipped.

if (validationFailures.Any()) { validationFailures.ToList(); foreach (var failure in validationFailures.ToList()) list.Items.Add(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve); } else list.Items.Add("All ok");

Originally created by @Manfrons on GitHub (Jan 23, 2020). Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/12 It seems that after iterate over the failures collection, calling ToList() or ToArray() doesn't populate it again. You can test with this code. I've generated an xml license file (copy/paste from main page), changed the expiration date inside the xml file and called the verification. Any returns true, but the foreach is skipped. ` if (validationFailures.Any()) { validationFailures.ToList(); foreach (var failure in validationFailures.ToList()) list.Items.Add(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve); } else list.Items.Add("All ok");`
Author
Owner

@sylvainonweb commented on GitHub (Mar 31, 2020):

Hi @Manfrons, I also encountered this errror and the solution was to call validationFailures.ToList() to retrieve the failures. This was written on the README.MD page.

Make sure to call validationFailures.ToList() or validationFailures.ToArray() before using the result multiple times.

            var failures = validationFailures.ToList();
            if (failures.Count > 0)
            {
                StringBuilder builder = new StringBuilder();
                foreach (var failure in failures)
                {
                    builder.AppendLine(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve);
                }
            }
<!-- gh-comment-id:606762941 --> @sylvainonweb commented on GitHub (Mar 31, 2020): Hi @Manfrons, I also encountered this errror and the solution was to call validationFailures.ToList() to retrieve the failures. This was written on the README.MD page. > Make sure to call validationFailures.ToList() or validationFailures.ToArray() before using the result multiple times. ``` var failures = validationFailures.ToList(); if (failures.Count > 0) { StringBuilder builder = new StringBuilder(); foreach (var failure in failures) { builder.AppendLine(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve); } } ```
Author
Owner

@dragonfly22000 commented on GitHub (May 7, 2020):

Hello, i have the same problem.....
What i do:
StringBuilder sb = new StringBuilder(); var license = Standard.Licensing.License.Load(text); var validationFailures = license.Validate() .ExpirationDate() .When(lic => lic.Type == LicenseType.Trial) .And() .Signature(publicKey) .AssertValidLicense(); var failures = validationFailures.ToList(); if (failures.Count > 0) { StringBuilder builder = new StringBuilder(); foreach (var failure in failures) { builder.AppendLine(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve); } }

When i change date in License file to have a failure i have an exception before putting something in failures list....
Help me please,thanks a lot.

<!-- gh-comment-id:625318275 --> @dragonfly22000 commented on GitHub (May 7, 2020): Hello, i have the same problem..... What i do: `StringBuilder sb = new StringBuilder(); var license = Standard.Licensing.License.Load(text); var validationFailures = license.Validate() .ExpirationDate() .When(lic => lic.Type == LicenseType.Trial) .And() .Signature(publicKey) .AssertValidLicense(); var failures = validationFailures.ToList(); if (failures.Count > 0) { StringBuilder builder = new StringBuilder(); foreach (var failure in failures) { builder.AppendLine(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve); } }` When i change date in License file to have a failure i have an exception before putting something in failures list.... Help me please,thanks a lot.
Author
Owner

@sylvainonweb commented on GitHub (May 7, 2020):

@dragonfly22000 it seems to be because the date you entered isn't a valid date.
On my side I tried with a file like this

<License>
  <Id>5f39c964-d48e-4da0-a06f-18fed6c8fb9c</Id>
  <ProductFeatures>
    <Feature name="XXXX">true</Feature>
  </ProductFeatures>
  <Customer>
    <CustomerData name="Name">YYY</CustomerData>
  </Customer>
  <Expiration>Sat, 06 Jun 2020 17:03:53 GMT</Expiration>
  <Signature>MEUCIQCqiackGvfmsEviUw9BN7v9bkFFktIrOORlUyEalXhWkAIgIz24qoAbAC9S1dQEswK92jC/kHYLV73dDcG6yB2ZprY=</Signature>
</License>
  1. I change the date for something like this Sat, 13 Jun 2020 17:03:53 GMT so

InvalidSignatureValidationFailure: License signature validation error! - The license signature and data does not match. This usually happens when a license file is corrupted or has been altered.

  1. I change the date for something like this Sat, 06 Jun 2021 17:03:53 GMT so

System.FormatException: 'String 'Sat, 06 Jun 2021 17:03:53 GMT' was not recognized as a valid DateTime because the day of week

=> certainly need to change the library to take it into account or do a try/catch for this kind of error and return that the license is invalid.

<!-- gh-comment-id:625383508 --> @sylvainonweb commented on GitHub (May 7, 2020): @dragonfly22000 it seems to be because the date you entered isn't a valid date. On my side I tried with a file like this ``` <License> <Id>5f39c964-d48e-4da0-a06f-18fed6c8fb9c</Id> <ProductFeatures> <Feature name="XXXX">true</Feature> </ProductFeatures> <Customer> <CustomerData name="Name">YYY</CustomerData> </Customer> <Expiration>Sat, 06 Jun 2020 17:03:53 GMT</Expiration> <Signature>MEUCIQCqiackGvfmsEviUw9BN7v9bkFFktIrOORlUyEalXhWkAIgIz24qoAbAC9S1dQEswK92jC/kHYLV73dDcG6yB2ZprY=</Signature> </License> ``` 1) I change the date for something like this **Sat, 13 Jun 2020 17:03:53 GMT** so > > InvalidSignatureValidationFailure: License signature validation error! - The license signature and data does not match. This usually happens when a license file is corrupted or has been altered. 2) I change the date for something like this **Sat, 06 Jun 2021 17:03:53 GMT** so > System.FormatException: 'String 'Sat, 06 Jun 2021 17:03:53 GMT' was not recognized as a valid DateTime because the day of week => certainly need to change the library to take it into account or do a try/catch for this kind of error and return that the license is invalid.
Author
Owner

@dragonfly22000 commented on GitHub (May 8, 2020):

@sylvainonweb Thanks for the answer ,effectively, i'm going to put a Try catch and make a pop-up in case of exception.
Thank you again.

<!-- gh-comment-id:625729543 --> @dragonfly22000 commented on GitHub (May 8, 2020): @sylvainonweb Thanks for the answer ,effectively, i'm going to put a Try catch and make a pop-up in case of exception. Thank you again.
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#10
No description provided.