NullReferenceException: Object reference not set to an instance of an object.

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
lfernandes
User
Posts: 77

NullReferenceException: Object reference not set to an instance of an object.

Post by lfernandes »

I would like to know if it is possible to use the CurrentUserInfo() function inside the Api_Action, because the error described below always occurs:

An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetMaker2021.Models.ead.CurrentUserInfo(string fldname) in aspnetfn.cs, line 1139

Stack Query Cookies Headers Routing
NullReferenceException: Object reference not set to an instance of an object.
AspNetMaker2021.Models.ead.CurrentUserInfo(string fldname) in aspnetfn.cs
AspNetMaker2021.Controllers.ListaPolosController.Get(int param) in apicontroller.cs
lambda_method185(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

MichaelG
User
Posts: 1122

Post by MichaelG »

Please make sure that you have set up Language/Profile/Security first. For example:

Language = ResolveLanguage();
Profile = ResolveProfile();
Security = ResolveSecurity();


lfernandes
User
Posts: 77

Post by lfernandes »

Thanks Michael, I included the code and it worked, although I didn't understand... could you please explain what these lines of code do and in what situation should I use them

Thank you very much in advance.


MichaelG
User
Posts: 1122

Post by MichaelG »

The codes are used to set up the Language/Profile/Security object. It should always be used if you have enabled security in your project.


Post Reply