PSU 4.0.12 Issue Create/Edit Schedule with GUI

Product: PowerShell Universal on IIS Server (Windows 2019)
Version: 4.0.12

Note : Issues created on GitHub
https://github.com/ironmansoftware/issues/issues/2659

I have an issue create/editing a schedule job with PSU Gui for Script using parameters. SomeBody could help me ?As soon as a script requires a parameter I get a 500 error.

Bug reproduction:

Create the following script:

param (
	[String[]]$tests
)

foreach($test in $tests){
    Write-Information $test

}

Create a schedule job with PowershellUniversal GUI

Result :
0CyTicmT5d

Web error (developer mode) :
POST https://xxxxxxxxxxxxx/api/v1/schedule 500 (Internal Server Error)
Response : Object reference not set to an instance of an object.

IIS logs :
Note : I replaced sensitive information with “xxxxxxxxxxxx”

[11:04:47 INF] Request starting HTTP/1.1 POST https://xxxxxxxxxxxxxxxxxx/api/v1/schedule application/json;charset=UTF-8 267
[11:04:47 VRB] All hosts are allowed.
[11:04:47 INF] Evaluting claims for xxxxxxxxxxxxxxxxxx, Cache: True
[11:04:47 VRB] This request accepts compression.
[11:04:47 DBG] The request has an origin header: 'https://xxxxxxxxxxxxxxxxxx'.
[11:04:47 INF] CORS policy execution failed.
[11:04:47 INF] Request origin https://xxxxxxxxxxxxxxxxxx does not have permission to access the resource.
[11:04:47 VRB] Adding HSTS header to response.
[11:04:47 VRB] Performing protect operation to key {xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx} with purposes ('C:\inetpub\wwwroot\', 'SessionMiddleware').
[11:04:47 DBG] POST requests are not supported
[11:04:47 DBG] POST requests are not supported
[11:04:47 DBG] Request matched endpoint 'UniversalAutomation.ScheduleController.Post (Universal.Server)'
[11:04:47 INF] Evaluting claims for xxxxxxxxxxxxxxxxxx, Cache: True
[11:04:47 INF] Executing endpoint 'UniversalAutomation.ScheduleController.Post (Universal.Server)'
[11:04:47 INF] Route matched with {action = "Post", controller = "Schedule"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Post(PowerShellUniversal.Schedule) on controller UniversalAutomation.ScheduleController (Universal.Server).
[11:04:47 DBG] Execution plan of authorization filters (in the following order): ["None"]
[11:04:47 DBG] Execution plan of resource filters (in the following order): ["Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter"]
[11:04:47 DBG] Execution plan of action filters (in the following order): ["Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter (Order: -2147483648)", "Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter (Order: -3000)"]
[11:04:47 DBG] Execution plan of exception filters (in the following order): ["None"]
[11:04:47 DBG] Execution plan of result filters (in the following order): ["Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter"]
[11:04:47 VRB] Resource Filter: Before executing OnResourceExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
[11:04:47 VRB] Resource Filter: After executing OnResourceExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
[11:04:47 DBG] Executing controller factory for controller UniversalAutomation.ScheduleController (Universal.Server)
[11:04:47 DBG] Executed controller factory for controller UniversalAutomation.ScheduleController (Universal.Server)
[11:04:47 DBG] Attempting to bind parameter 'schedule' of type 'PowerShellUniversal.Schedule' ...
[11:04:47 DBG] Done attempting to bind parameter 'schedule' of type 'PowerShellUniversal.Schedule'.
[11:04:47 DBG] Attempting to validate the bound parameter 'schedule' of type 'PowerShellUniversal.Schedule' ...
[11:04:47 DBG] Done attempting to validate the bound parameter 'schedule' of type 'PowerShellUniversal.Schedule'.
[11:04:47 VRB] Action Filter: Before executing OnActionExecutionAsync on filter Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter.
[11:04:47 VRB] Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
[11:04:47 VRB] Action Filter: After executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
[11:04:47 INF] Executing action method UniversalAutomation.ScheduleController.Post (Universal.Server) - Validation state: Valid
[11:04:47 VRB] Executing action method UniversalAutomation.ScheduleController.Post (Universal.Server) with arguments (["test"])
[11:04:47 VRB] Action Filter: Before executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
[11:04:47 VRB] Action Filter: After executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
[11:04:47 VRB] Action Filter: After executing OnActionExecutionAsync on filter Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter.
[11:04:47 VRB] Resource Filter: Before executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
[11:04:47 VRB] Resource Filter: After executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
[11:04:47 INF] Executed action UniversalAutomation.ScheduleController.Post (Universal.Server) in 3.9066ms
[11:04:47 INF] Executed endpoint 'UniversalAutomation.ScheduleController.Post (Universal.Server)'
[11:04:47 ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at UniversalAutomation.PowerShellSerializer`1.Serialize(IEnumerable`1 items) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\PowerShellSerializer.cs:line 391
   at UniversalAutomation.Services.ConfigurationScript`1.WriteAsync(T item, Identity identity) in C:\actions-runner\_work\universal\universal\src\PowerShellUniversal\ConfigurationScript.cs:line 135
   at UniversalAutomation.Services.SchedulesConfigurationScript.WriteAsync(Schedule item, Identity identity) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Configuration\Schedules.cs:line 61
   at UniversalAutomation.Services.UniversalConfigurationService.WriteAsync(Object item, Identity identity) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 272
   at UniversalAutomation.Services.UniversalConfigurationService.WriteAndSyncAsync[T](T item, Identity identity) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 249
   at UniversalAutomation.ScheduleController.Post(Schedule schedule) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Controllers\ScheduleController.cs:line 111
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at PowerShellUniversal.PSUMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\PowerShellMiddleware.cs:line 44
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at PowerShellUniversal.FeatureMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\FeatureMiddleware.cs:line 43
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at PowerShellUniversal.DisallowedModeMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\ModeMiddleware.cs:line 47
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at PowerShellUniversal.CspMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\CspMiddleware.cs:line 21
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Universal.Server.Middleware.RoutingMiddleware.Invoke(HttpContext httpContext, IPolicyEvaluator policyEvaluator) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\RoutingMiddleware.cs:line 202
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Universal.Server.Middleware.SwaggerAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\SwaggerAuthMiddleware.cs:line 37
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) in C:\actions-runner\_work\universal\universal\src\AspNetCoreRateLimit\Middleware\RateLimitMiddleware.cs:line 110
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
[11:04:47 DBG] No response compression available for HTTPS requests. See ResponseCompressionOptions.EnableForHttps.
[11:04:47 INF] Request finished HTTP/1.1 POST https://xxxxxxxxxxxxxxxxxx/api/v1/schedule application/json;charset=UTF-8 267 - 500 - text/plain 11.9579ms

For those who encounter the same problem, it is possible to get around this bug by directly creating the schedule in schedules.ps1

PSU interface :

Adding line like this :
New-PSUSchedule -Cron "0 8 * * *" -Script "test.ps1" -TimeZone "Europe/Paris" -tests @('firststring', 'secondstring', 'thridstring') -Name "test"

I’ve actually seen a few of these errors in the latest versions, I’m currently on 4.0.10 and I’ve had the same error when trying to change settings (happened on a couple of different occasions), ended up just doing it in the back end settings.ps1 file.