XenDesktop Licensing Service Crashes on License Addition

Hang on, I'm primarily a VMware virtualization focused blogger aren't I? Mostly, yes, but there are environments I work on that have other virtualization products installed in them. One of these, a PoC for a project, had a XenDesktop Express installation running in it that had an expired trial license.

I was able to retrieve a new license file from Citrix's website…

…and sought to use the Desktop Studio to apply it. However, I received a message back during the process to say that the License Server was not available:

Error code:
Citrix License Server currently unavailable. Check the license server and make sure it's running, then try again.

==============================

Exception:
System.Reflection.TargetInvocationException Exception has been thrown by the target of an invocation.
at Citrix.Console.Common.CallbackEventArguments.OperationCompleteSynchronizer`1.GetResults()
at Citrix.Console.Common.CallbackEventArguments.OperationCompleteSynchronizer`1.WaitForResults()
at Citrix.Console.UI.Licensing.Mmc.LicensingResultPaneViewModel.UploadFileToLicenseServer(String fileName, Boolean overwrite)
at Citrix.Console.UI.Licensing.Mmc.LicensingResultPaneViewModel.c__DisplayClass20.<;AddLicense&gt;b__1e()
at Citrix.Console.CommonControls.ProgressDisplay.GenericProgressOperation.PerformOperationInternal()
at Citrix.Console.CommonControls.ProgressDisplay.ProgressWindowOperation.PerformOperation()
at Citrix.Console.CommonControls.ProgressDisplay.ProgressWindowViewModel.PerformAction(ManualResetEvent operationComplete)

Inner exception:
Citrix.Console.Models.CallbackEventArguments.ScriptException Citrix License Server currently unavailable. Check the license server to make sure it's running, then try again.
at Citrix.Console.PowerShellInteraction.XDCommand.EndExecutionAndCheckErrors(ProgressModel progressModel)
at Citrix.Console.PowerShellInteraction.XDCommand.RunTypeUnsafe()
at Citrix.Console.PowerShellSdk.LicensingService.Scripts.AddLicenseFileScript.RunScript()
at Citrix.Console.PowerShellInteraction.ThreadedPowerShellScript`1.RunScriptInternal()

Error data:
LicenseServerDownnSystem.InvalidOperationException: License Server is not running.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

=========================================================================

A quick look in the Windows Services tool showed that it was indeed not running. Restarting it only produced another failure and a Windows 1067 error.

It turns out that when trying to download the license file it had in fact downloaded the web page's source into the .lic file instead of the license text! Just opening the license file showed this. Scrolling down though you find the real URL for the license file:

Just pop that into your browser address bar and download the file.

Of course, the Licensing Server still won't start as it's trying to read the incorrectly populated license file and failing. To resolve this, just delete the .lic file that it has tried to import from c:program files(x86)citrixlicensingmyfiles:

The service will now start again and you can import the correct license file.