The remote server returned an error: (500) Internal Server Error

I am using UD Community 2.9.0.
While executing below script

Enable-UDLogging
Start-UDRestApi -Name JustEndPoint -Debug -Port 1000    -Endpoint @(
New-UDEndpoint -Url "user" -Method "GET" -Endpoint {
    @("Adam", "Sarah", "Bill") | ConvertTo-Json
} )

try
{
	Invoke-RestMethod http://localhost:1000/api/user
}
catch
{
        $_.Exception
}

Get-UDRestApi -Name JustEndPoint  | Stop-UDRestApi

I get (500) Internal Server Error. Is that something to do with installation or environment ? I had tried same script in some other machine and it worked fine.

Log details below.

PS <SOME_FOLDER>> .\JustEndPoint.ps1
21:16:24 [Debug] EndpointService Register() aabef67a-4248-444f-b30e-67bf936bf931 user
21:16:24 [Info] StartDashboardCommand JustEndPoint - D:\DBA_WebSite\JustEndPoint.ps1 - False
21:16:25 [Debug] CustomAssemblyLoadContext Pointer Size:8
21:16:25 [Debug] CustomAssemblyLoadContext Loading files in native directory: C:\Program Files\WindowsPowerShell\Modules\UniversalDashboard\2.9.0\net472\runtimes\win-x64\native
21:16:25 [Debug] EndpointService Register() aabef67a-4248-444f-b30e-67bf936bf931 user
21:16:25 [Debug] EndpointService Register() aabef67a-4248-444f-b30e-67bf936bf931 user
21:16:25 [Debug] PowerShellExecutionService ExecutionService constructor
21:16:25 [Info] Quartz.Impl.StdSchedulerFactory Using object serializer: Quartz.Simpl.BinaryObjectSerializer, Quartz
21:16:26 [Debug] Quartz.Simpl.TaskSchedulingThreadPool TaskSchedulingThreadPool configured with max concurrency of 100 and TaskScheduler ThreadPoolTaskScheduler.
21:16:26 [Info] Quartz.Core.SchedulerSignalerImpl Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl
21:16:26 [Info] Quartz.Core.QuartzScheduler Quartz Scheduler v.3.0.6.0 created.
21:16:26 [Info] Quartz.Simpl.RAMJobStore RAMJobStore initialized.
21:16:26 [Info] Quartz.Core.QuartzScheduler Scheduler meta-data: Quartz Scheduler (v3.0.6.0) 'QuartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'Quartz.Core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'Quartz.Simpl.DefaultThreadPool' - with 100 threads.
  Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.

21:16:26 [Info] Quartz.Impl.StdSchedulerFactory Quartz scheduler 'QuartzScheduler' initialized
21:16:26 [Info] Quartz.Impl.StdSchedulerFactory Quartz scheduler version: 3.0.6.0
21:16:26 [Info] Quartz.Core.QuartzScheduler Scheduler QuartzScheduler_$_NON_CLUSTERED started.
21:16:26 [Debug] Quartz.Core.QuartzSchedulerThread Batch acquisition of 0 triggers
21:16:26 [Debug] Quartz.Core.QuartzSchedulerThread Batch acquisition of 1 triggers
21:16:26 [Debug] Quartz.Simpl.SimpleJobFactory Producing instance of Job 'DEFAULT.e5c9d9ca-ba73-4673-9c98-88afe68d14cd', class=UniversalDashboard.Services.LicenseCheckJob
21:16:26 [Debug] Quartz.Core.QuartzSchedulerThread Batch acquisition of 1 triggers
21:16:26 [Debug] Quartz.Simpl.SimpleJobFactory Producing instance of Job 'DEFAULT.4e57dcfb-00a9-4156-9c66-8ee18deec029', class=UniversalDashboard.Services.LicenseExpirationJob

21:16:26 [Debug] Quartz.Core.QuartzSchedulerThread Batch acquisition of 0 triggers
21:16:26 [Debug] Quartz.Core.JobRunShell Calling Execute on job DEFAULT.e5c9d9ca-ba73-4673-9c98-88afe68d14cd
21:16:26 [Debug] Quartz.Core.JobRunShell Calling Execute on job DEFAULT.4e57dcfb-00a9-4156-9c66-8ee18deec029
21:16:26 [Debug] LicenseExpirationJob License count: System.Collections.Generic.List`1[UniversalDashboard.Services.LicensedDashboard]
21:16:26 [Debug] Quartz.Core.JobRunShell Trigger instruction : NoInstruction
21:16:26 [Debug] Quartz.Core.JobRunShell Trigger instruction : NoInstruction
21:16:27 [Info] Microsoft.AspNetCore.Hosting.Internal.WebHost Request starting HTTP/1.1 GET http://localhost:1000/api/user
21:16:27 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Route matched with {action = "GetEndpoint", controller = "Component"}. Executing action UniversalDashboard.Controllers.ComponentController.GetEndpoint (UniversalDashboard)
21:16:27 [Debug] PowerShellExecutionService ExecutionService constructor
21:16:27 [Debug] PowerShellExecutionService ExecutionService constructor
21:16:27 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executing action method UniversalDashboard.Controllers.ComponentController.GetEndpoint (UniversalDashboard) - Validation state: Valid
21:16:27 [Info] ComponentController GetEndpoint - user
21:16:27 [Debug] AuthorizationService TryRunClaimsAuthorization
21:16:27 [Debug] AuthorizationService Session ID: c5d041b3-63ec-4f84-9a88-ecb22c8df4af
21:16:27 [Debug] AuthorizationService No valid authorization policies for session.
21:16:27 [Debug] AuthorizationService No valid roles for session.
21:16:27 [Debug] AuthorizationService Setting access and ID token.
21:16:27 [Debug] AuthorizationService No authorization policies or roles defined.
21:16:27 [Warn] ComponentController RunScript() Cannot overwrite variable Error because it is read-only or constant.
   at System.Management.Automation.SessionStateScope.SetVariable(String name, Object value, Boolean asValue, Boolean force, SessionStateInternal sessionState, CommandOrigin origin, Boolean fastPath)
   at System.Management.Automation.SessionStateInternal.SetVariableAtScope(PSVariable variable, String scopeID, Boolean force, CommandOrigin origin)
   at System.Management.Automation.SessionStateInternal.AddSessionStateEntry(SessionStateVariableEntry entry)
   at System.Management.Automation.Runspaces.InitialSessionState.Bind(ExecutionContext context, Boolean updateOnly, PSModuleInfo module, Boolean noClobber, Boolean local)
   at System.Management.Automation.AutomationEngine..ctor(PSHost hostInterface, RunspaceConfiguration runspaceConfiguration, InitialSessionState iss)
   at System.Management.Automation.Runspaces.LocalRunspace.DoOpenHelper()
   at System.Management.Automation.Runspaces.RunspaceBase.CoreOpen(Boolean syncCall)
   at UniversalDashboard.Services.UDRunspaceFactory.CreateRunspace()
   at UniversalDashboard.Services.ObjectPool`1.CreateInstance()
   at UniversalDashboard.Services.ObjectPool`1.AllocateSlow()
   at UniversalDashboard.Services.ObjectPool`1.Allocate()
   at UniversalDashboard.Services.UDRunspaceFactory.GetRunspace()
   at UniversalDashboard.Execution.PowerShellExecutionService.ExecuteEndpoint(ExecutionContext context, AbstractEndpoint endpoint)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UniversalDashboard.Execution.PowerShellExecutionService.<ExecuteEndpointAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UniversalDashboard.Execution.ExecutionService.<ExecuteEndpointAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UniversalDashboard.Controllers.ComponentController.<RunScript>d__8.MoveNext()
21:16:27 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executed action UniversalDashboard.Controllers.ComponentController.GetEndpoint (UniversalDashboard) in 138.3565ms
21:16:27 [Info] Microsoft.AspNetCore.Session.DistributedSession Session started; Key:1bfe5d41-5916-6296-5af7-65d817b74bc4, Id:0d659266-88c0-8f0f-622f-a47693dd4c7e
21:16:27 [Error] Microsoft.AspNetCore.Server.Kestrel Connection id "0HM07QL3EK6LC", Request id "0HM07QL3EK6LC:00000001": An unhandled exception was thrown by the application.
21:16:27 [Info] Microsoft.AspNetCore.Hosting.Internal.WebHost Request finished in 593.7789ms 500
Name         Port Running DashboardService
----         ---- ------- ----------------
JustEndPoint 1000    True UniversalDashboard.Services.DashboardService
The remote server returned an error: (500) Internal Server Error.
21:16:27 [Debug] GetRestApiCommand Name: JustEndPoint
21:16:28 [Debug] StopRestApiCommand ByServer
21:16:28 [Debug] LicenseManager Return License: SGSINVMPDBTSQ01, 1000, Licenses in use: 0
21:16:28 [Debug] LicenseManager Licenses in use: 0


PS <SOME_FOLDER>> 21:16:28 [Info] Quartz.Core.QuartzScheduler Scheduler QuartzScheduler_$_NON_CLUSTERED shutting down.
21:16:28 [Info] Quartz.Core.QuartzScheduler Scheduler QuartzScheduler_$_NON_CLUSTERED paused.
21:16:28 [Debug] Quartz.Simpl.TaskSchedulingThreadPool Shutting down threadpool...
21:16:28 [Debug] Quartz.Simpl.TaskSchedulingThreadPool Shutdown of threadpool complete.
21:16:28 [Info] Quartz.Core.QuartzScheduler Scheduler QuartzScheduler_$_NON_CLUSTERED Shutdown complete.

Hi!

It’s very likley, especially if you tried the same on another machine and don’t have the issue there. I used to get 500 errors when setting up a new UD instance in IIS if I’d missed something with my config. Can we get more details on your installation & environment?

Where are you hosting UD, is this a service, just running in console, hosted in IIS?
Do you have all the pre-reqs installed and configured where required?
Are you running on windows or linux?
Comparing to your other server where you do have this working, are there any differences (in OS, PS version, .net etc)

Thanks for attending this post :slight_smile:

Please see my response to your question below.

Where are you hosting UD, is this a service, just running in console, hosted in IIS?

I am just running this on console.

Do you have all the pre-reqs installed and configured where required?

I followed the pre-requistes as per the this link

Are you running on windows or linux?

On Windows

Comparing to your other server where you do have this working, are there any differences (in OS, PS version, .net etc)

Both are virtual machines with OS Windows Server 2012 R2. I could see that PS versions are different in both machines. i.e 5.0.10586.117(Where it is not working) and 5.1.14409.1018(Where it is working)

I managed to upgrade the PS version to 5.1. It is working fine now. It is an oversight from my end.