Undocumented .NET licensing model problems RRS feed

  • Question

  • Hi,
    I saw this problem a lot of time. When I have my own License class implementation and call LicenseManager.IsValid, it is often situation that IsValid returns True (i.e. license is valid), however, license itself (out parameter that must save valid license) is set to null. Microsoft doesn't comment this problem in MSDN documentation, they just write that "it is possible that license is set to null when IsValid returns true". No one word about why the license is null and how to avoid it. This problem makes Microsoft's licensing model fully not useful, because in this case we just know if user has any license, we don't even know is it trial or commersial one.
    Actually for me in some applications it returns null and in other ones it retuns license instance. And I can not forecast when it decides to return null.
    Does anyone know why LicenseManager.IsValid often returns null even when license is valid and how to avoid it? Because in any licensing scenario except the most primitive check "valid - invalid" we need license instance for further checks and not just to know that some license with unknown parameters is present.
    Wednesday, March 3, 2010 6:55 PM

All replies

  • I never played with LicenseManager, but the documentation says:
        1. The IsValid method returns true when the type parameter is not licensed, or when it is licensed and the license parameter is valid.
        2. license parameter - A License that is a valid license, or nullNothingnullptra null reference (Nothing in Visual Basic) if a valid license cannot be granted. 
        3. This method does not throw a LicenseException when it cannot grant a valid License. The Validate method throws exceptions.

    I read it that either:
      - your type is not licensed (and therefore you get true and null) and you can probably call IsLicensed to figure that out, or
      - the license cannot be granted (whatever that means) and you can call Validate to get exception (not sure if that helps), or
      - there is a bug in LicenseManager. If it is a bug, then please create a small repro and file a bug on Microsoft Connect.

    Wednesday, March 3, 2010 10:57 PM
  • Yes, really, I read this MSDN help topic. I debugged my custom LicenseProvider. It really creates license, created license is valid; I debug up to return statement from LicenseProvider.GetLicense() (this method is called by LicenseManager in IsValid method). So valid license is really generated. However, when return statement is executed in GetLicense(), I see that LicenseManager calls Dispose method on this license. I can not find any reason in documentation why LicenseManager disposes license generated during IsValid call. When license is disposed, IsValid() returns True and null license. Without any explanation why it did so. The same problem I saw a lot of times, possibly some behaviors of LicenseProvider are not documented, because the same works in some applications and doesn't in other ones; I even saw that when I move license check code from one class to another in the same application, it some times works and some times not.
    Thursday, March 4, 2010 8:03 AM