dnauck / Portable.Licensing

Portable.Licensing is a cross platform software licensing framework which allows you to implement licensing into your application or library. It provides you all tools to create and validate licenses for your software.
http://dev.nauck-it.de/projects/portable-licensing
MIT License
592 stars 173 forks source link

Expiration date parsing exception not handled #26

Open NoahStahl opened 9 years ago

NoahStahl commented 9 years ago

When testing modifying the expiration date in the license file, it appears that the DateTime parsing exceptions are not handled and translated into a proper IValidationResult. Instead, an exception is thrown as soon as the result is accessed. An example exception: "String was not recognized as a valid DateTime because the day of week was incorrect."

I'm working around this by surrounding my validation check in a try block, but it would be nice for invalid expiration dates to trigger the normal "License signature validation error" message.

Great work, thanks for this!

dnauck commented 9 years ago

Could you please post a complete stack trace of that exception?

NoahStahl commented 9 years ago

Sure:

System.FormatException: String was not recognized as a valid DateTime because the day of week was incorrect.

Stack trace:

at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) at System.DateTime.ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style) at Portable.Licensing.License.get_Expiration() at Portable.Licensing.Validation.LicenseValidationExtensions.b1(License license) at Portable.Licensing.Validation.ValidationChainBuilder.d1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

sjdirect commented 8 years ago

I'm having the same issue...

See related github issue here

<Expiration>Fri, 31 Dec 9999 23:59:59 GMT</Expiration>

This date blows up on just some of my customer's machines. I have not been able to repro on any environment. Below is a screenshot that one of them sent me.

c9129384-a70f-11e5-9b0e-774c8adc56ee .

sjdirect commented 8 years ago

Looks like when you have a license with a expiration date of DateTime.MaxValue which is (Fri, 31 Dec 9999 23:59:59 GMT), some version of visual studio/.net fail. I was unable to replicate this on vs 2012, 2013, 2015 but other user's of my project were.

My solution was to generate a permanent license that expires in a 100 years instead of using DateTime.MaxValue.