0

I created a .NET Core WebAPI with Version 2.1. Now i moved to software to the production server, after all tests finished successfully on an external test server. The configuration of the servers is the same, both use Ubuntu 18.04.03. Only the Version of the framework are different, on the production server runs 2.1.15, on the test-servers runs 2.1.12.

The following code works on the local development machine and on the external test server, but crashed on the external production server.

        [HttpPost]
        [Authorize]
        public IActionResult Post([FromBody] PetItem pet)
        {
            var user = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name);
            int userID = Convert.ToInt16(user.Value);

            pet.CreatorID= userID; //System.NullReferenceException

            var returnPet = _petDataHandler.createNewPet(pet);

            return Created(returnPet.PetID.ToString(), returnPet;
        }

Log:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
       Connection id "0HLTOVB6C8I6O", Request id "0HLTOVB6C8I6O:00000003": An unhandled exception was thrown by the application.
 System.NullReferenceException: Object reference not set to an instance of an object.
    at server.Pets.Controllers.PetController.Post(PetItem pet) in D:\...\server\Pet\Controllers\PetController.cs:line 75
    at lambda_method(Closure , Object , Object[] )
    at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
    at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
    at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)


What is my mistake, knows anybody a solution for this problem.

KreLou
  • 115
  • 1
  • 2
  • 10
  • 1
    pet is null, simple as that, if you figure that out, you will figure out your problem – TheGeneral Feb 24 '20 at 07:44
  • No pet is not null, i checked it with a (pet == null) and this returns false. I also tried to check (user == null). – KreLou Feb 24 '20 at 08:04
  • have some sort of logging mechanism on the production server. that way you can log whatever you're sending to the API and you can take it from there. – Andrei Dragotoniu Feb 24 '20 at 09:30
  • Not really, I implemented some Console.WriteLine() for printing the current instance of pet and user. The PetItem is complete and successfully passed all ModelState-checks – KreLou Feb 24 '20 at 09:33

0 Answers0