EnsureUserSet error, User has not been set.
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When accessing /scripts/script-schedules and device-details/ad0feca9-7e34-4019-9a0b-0cde9f2f382e/remote-logs,
I encounter an authentication error. There are no issues with other parts of the application.
**To Reproduce**
```
System.InvalidOperationException: User has not been set.
at Remotely.Server.Components.AuthComponentBase.EnsureUserSet() in C:\repos\Remotely\Server\Components\AuthComponentBase.cs:line 28
at Remotely.Server.Components.Scripts.ScriptSchedules.get_CanModifySchedule() in C:\repos\Remotely\Server\Components\Scripts\ScriptSchedules.razor.cs:line 55
```
**Remotely Version**
Server (can be found on about page): 2023.09.11.1010
Agent (can be found in device card): 2023.09.11.1010
**Expected Behavior**
The feature itself does not work.
**Screenshots**
none.
**Desktop (please complete the following information):**
- OS: Windows 11
- Browser Chrome
- Version 119.0.6045.199
**Additional Context**
```c
2023-12-01 03:14:23.847 +00:00 [ERR] An unhandled exception has occurred while executing the request. { EventId: { Id: 1, Name: "UnhandledException" }, SourceContext: "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware", RequestId: "0HMVI3EF3GJTP:00000001", RequestPath: "/scripts/script-schedules", ConnectionId: "0HMVI3EF3GJTP", ThreadId: 15 }
System.InvalidOperationException: User has not been set.
at Remotely.Server.Components.AuthComponentBase.EnsureUserSet() in C:\repos\Remotely\Server\Components\AuthComponentBase.cs:line 28
at Remotely.Server.Components.Scripts.ScriptSchedules.get_CanModifySchedule() in C:\repos\Remotely\Server\Components\Scripts\ScriptSchedules.razor.cs:line 55
at Remotely.Server.Components.Scripts.ScriptSchedules.b__38_1(RenderTreeBuilder __builder2)
at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentAsync(Int32 componentId, ParameterView initialParameters)
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.RenderComponentAsync(Type componentType, ParameterView initialParameters)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c__11`1.<b__11_0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.PrerenderComponentAsync(ParameterView parameters, HttpContext httpContext, Type componentType)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.PrerenderedServerComponentAsync(HttpContext context, ServerComponentInvocationSequence invocationId, Type type, ParameterView parametersCollection)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.RenderComponentAsync(ViewContext viewContext, Type componentType, RenderMode renderMode, Object parameters)
at Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
at Remotely.Server.Pages.Pages__Host.<>c__DisplayClass21_0.<b__1>d.MoveNext() in C:\repos\Remotely\Server\Pages\_Host.cshtml:line 61
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()
at Remotely.Server.Pages.Pages__Host.ExecuteAsync() in C:\repos\Remotely\Server\Pages\_Host.cshtml:line 13
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.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.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
2023-12-01 03:14:52.219 +00:00 [WRN] Unhandled exception rendering component: User has not been set. { EventId: { Id: 100, Name: "ExceptionRenderingComponent" }, SourceContext: "Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer", TransportConnectionId: "G6iOm4yN3ofTPGh4svTurw", RequestId: "0HMVI3EF3GJVR:00000001", RequestPath: "/_blazor", ConnectionId: "0HMVI3EF3GJVR", ThreadId: 23 }
System.InvalidOperationException: User has not been set.
at Remotely.Server.Components.AuthComponentBase.EnsureUserSet() in C:\repos\Remotely\Server\Components\AuthComponentBase.cs:line 28
at Remotely.Server.Components.Scripts.ScriptSchedules.get_CanModifySchedule() in C:\repos\Remotely\Server\Components\Scripts\ScriptSchedules.razor.cs:line 55
at Remotely.Server.Components.Scripts.ScriptSchedules.b__38_1(RenderTreeBuilder __builder2)
at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with Server/Components/AuthComponentBase.cs at EnsureUserSet and Server/Components/Scripts/ScriptSchedules.razor.cs at CanModifySchedule, then inspect Server/Pages/_Host.cshtml around the reported rendering path. Reproduce /scripts/script-schedules and the device remote-logs route; done means both features render without the reported User has not been set exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100