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