Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validationFailures.ToList() not working #12

Open
Manfrons opened this issue Jan 23, 2020 · 4 comments
Open

validationFailures.ToList() not working #12

Manfrons opened this issue Jan 23, 2020 · 4 comments

Comments

@Manfrons
Copy link

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");

@sylvainonweb
Copy link

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);
                }
            }

@dragonfly22000
Copy link

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.

@sylvainonweb
Copy link

@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.

@dragonfly22000
Copy link

@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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants