diff --git a/src/NServiceBus.Core/Licensing/LicenseManager.cs b/src/NServiceBus.Core/Licensing/LicenseManager.cs index 0fdade8ddab..4299f695620 100644 --- a/src/NServiceBus.Core/Licensing/LicenseManager.cs +++ b/src/NServiceBus.Core/Licensing/LicenseManager.cs @@ -4,6 +4,7 @@ namespace NServiceBus.Licensing using System.Threading; using System.Windows.Forms; using Logging; + using Microsoft.Win32; using Particular.Licensing; [ObsoleteEx(Message = "Not a public API.", TreatAsErrorFromVersion = "4.5", RemoveInVersion = "5.0")] @@ -78,20 +79,16 @@ internal static void InitializeLicense() //only do this if not been configured by the fluent API if (licenseText == null) { - //look in the new platform locations - if (!(new RegistryLicenseStore().TryReadLicense(out licenseText))) - { - //legacy locations - licenseText = LicenseLocationConventions.TryFindLicenseText(); + licenseText = GetExistingLicense(); + } - if (string.IsNullOrWhiteSpace(licenseText)) - { - license = GetTrialLicense(); - return; - } - } + if (string.IsNullOrWhiteSpace(licenseText)) + { + license = GetTrialLicense(); + return; } + LicenseVerifier.Verify(licenseText); var foundLicense = LicenseDeserializer.Deserialize(licenseText); @@ -114,6 +111,26 @@ internal static void InitializeLicense() license = foundLicense; } + static string GetExistingLicense() + { + string existingLicense; + + //look in HKCU + if (new RegistryLicenseStore().TryReadLicense(out existingLicense)) + { + return existingLicense; + } + + //look in HKLM + if (new RegistryLicenseStore(Registry.LocalMachine).TryReadLicense(out existingLicense)) + { + return existingLicense; + } + + + return LicenseLocationConventions.TryFindLicenseText(); + } + static ILog Logger = LogManager.GetLogger(typeof(LicenseManager)); static string licenseText; static Particular.Licensing.License license;