Base solution for your next web application
Open Closed

Can get entity from public website in dev environment, but it throws an error in production #9150


User avatar
0
marble68 created

I have a controller with a method where the ID of the entity is passed.

In my development environment, I can get the entity with no problems like this:


EmployeeDto employee = _employeesAppService.GetEmployeeForView(_id).Result.Employee;

Everything works great... unless I'm running in production.

In the MVC side, this function is called without issue.

For my public controller, I have:

So I deployed to producdtion, and I get an error saying there's no Entity by the ID.

I've verified I'm passing the correct ID, and I can see the ID in the database.


System.AggregateException: One or more errors occurred. (There is no such an entity. Entity type: okto.work.Survey.Employee, id: c6e010e3-f4d6-4241-c350-08d80a7ba1e1)

 ---> Abp.Domain.Entities.EntityNotFoundException: There is no such an entity. Entity type: okto.work.Survey.Employee, id: c6e010e3-f4d6-4241-c350-08d80a7ba1e1
 
   at Abp.Domain.Repositories.AbpRepositoryBase`2.GetAsync(TPrimaryKey id)
   
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   
   at okto.work.Survey.EmployeesAppService.GetEmployeeForView(Guid id) in C:\Program Files (x86)\Go Agent\pipelines\StagingPipeline\src\okto.work.Application\Survey\EmployeesAppService.cs:line 101
   
   

Am I missing something simple?

Any suggestions will be helpful.


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    Please use await to call asynchronous methods. This is important.

    EmployeeDto employee = (await _employeesAppService.GetEmployeeForView(_id)).Employee;
    

    there's no Entity by the ID.

    Is the Employee entity multi-tenant?

    You can set ASPNETCORE_ENVIRONMENT to Production when debugging applications locally.

  • User Avatar
    0
    marble68 created

    thabk you - i will try that

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @marble68

    Did that work for you ?

  • User Avatar
    0
    marble68 created

    Deploying to production now.

    Yes - the employee entity is multi-tenant.

  • User Avatar
    0
    marble68 created

    No, that did not work resolve the issue.

    I refactors my async call to use await instead of .Result, yet that did not address issue. I'm working to add more logging to determine what's failing.

  • User Avatar
    0
    maliming created
    Support Team

    @marble68

    Using await will not solve this problem, just prevent blocking. https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

    You can try it in chrome's incognito mode. If your entity is multi-tenant, you can check whether the current TenantId is expected.

  • User Avatar
    0
    marble68 created

    I think my issue is related to trying to get an entity across tenants from the public website.

    Because they have differnet URLs, it was breaking in production (admin.domain.com vs domain.com).

    In dev, they were both localhost.

    To recreate, I added two host entries for localhost (mvc & public) - and modified settings to use those urls in development.

    The result allowed me to recreate the problem in dev.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Then, if you know the target tenantId, you can switch tenant context as explained in https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants