PowerShell Universal Service crashes on startup after an upgrade to 1.4.6

PowerShell Universal Service crashes on startup after an upgrade to 1.4.6

Version: PowerShell Universal 1.4.6

Issue
The PowerShell Universal service will crash with the following error in Event Viewer. 

Application: Universal.Server.exe

CoreCLR Version: 4.700.19.56402

.NET Core Version: 3.1.0

Description: The process was terminated due to an unhandled exception.

Exception Info: System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[LiteDB.BsonValue]' to type 'System.String'.

   at lambda_method(Closure , Object , Object )

   at LiteDB.BsonMapper.DeserializeObject(Type type, Object obj, BsonDocument value)

   at LiteDB.BsonMapper.Deserialize(Type type, BsonValue value)

   at LiteDB.BsonMapper.ToObject(Type type, BsonDocument doc)

   at LiteDB.BsonMapper.ToObject[T](BsonDocument doc)

   at LiteDB.LiteCollection`1.Find(Query query, Int32 skip, Int32 limit)+MoveNext()

   at LiteDB.LiteQueryable`1.ToEnumerable()+MoveNext()

   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)

   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)

   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

   at LiteDB.LiteQueryable`1.ToArray()

   at UniversalAutomation.LiteDBTable`1.ToArray() in D:\a\universal\universal\src\UniversalAutomation.LiteDB\LiteDBDatabase.cs:line 527

   at UniversalAutomation.LiteDBTable`1.Get() in D:\a\universal\universal\src\UniversalAutomation.LiteDB\LiteDBDatabase.cs:line 470

   at Universal.Server.Services.SecurityProxy.Start() in D:\a\universal\universal\src\Universal.Server\Services\SecurityProxy.cs:line 51

   at UniversalAutomation.StartupService.StartAsync(CancellationToken cancellationToken) in D:\a\universal\universal\src\Universal.Server\Services\StartupService.cs:line 67

   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

   at Universal.Server.Program.Main(String[] args) in D:\a\universal\universal\src\Universal.Server\Program.cs:line 30

Root Cause

The PowerShell Universal Service may crash when upgrading from a version prior to 1.4.6 if you have previously configured arguments for environments that contain multiple arguments. To resolve this issue, you can delete the records in the local LiteDB database. The records will be recreated on start up of the service. 

Resolution
2. Stop the PowerShell Universal Service. 
3. Open the PowerShell Universal database file (defaults to C:\ProgramData\UniversalAutomation\database.db) in LiteDB Explorer. 
4. Double click on the ExecutionEnvironments table. 



5. Delete the execution environment with arguments listed (it will likely say [Array] in the arguments column). You can backup the database file if you like but the record will be recreated when the PowerShell Universal Service starts up and reads the environments.ps1 file. 



6. Close LiteDB Explorer
7. Start the PowerShell Universal server

    • Related Articles

    • PowerShell Universal crashes after upgrade to 1.5

      Version: 1.5 Issue: The PowerShell Universal service will not start properly when upgrading from 1.4 to 1.5. The following error is shown in the log.  Unhandled exception. System.InvalidCastException: Unable to cast object of type ...
    • PowerShell Universal server crashes with error "Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.DataPage'. "

      Version: 1.4.x Issue: An error is thrown when running jobs that states:       Error executing job 31: Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.DataPage'.    at LiteDB.PageService.GetPage[T](UInt32 pageID) This only happens ...
    • KB0069 - PowerShell Universal Startup Process

      Purpose The purpose of this document is to outline the steps that PowerShell Universal takes when starting up. Process 1. Insert current product version and install date in database Updates the database with a record about the current product version ...
    • KB0041 - About Templates

      Purpose The purpose of this article is to provide a timeline around the Template functionality of PowerShell Universal. Background Templates were introduced to provide a starting point for newcomers to PowerShell Universal. They have since been ...
    • KB0036 - How to set the license via environment variable

      Purpose The purpose of this article is to explain how to set the license for PowerShell Universal by way of environment variable instead of the traditional file-based method. Scope For now, only Windows is in the scope of this article. Linux and ...