Base solution for your next web application
Open Closed

System.ArgumentOutOfRangeException: #9977


User avatar
0
murphymj5209 created

I am on the current aspnetzero 10.1; using angular, EF; PowerTools 2.7.6

PowerTools has generated a good Entity for what it was designed todo. I created an Entity with 2 Navigation dropdowns. In one of the dropdowns, I want to display 2 fields from the table, instead of one; a simple concatination. The below does not work on the server side, both will return correct data, please let me know where to look to change the code. I do not think the angular side needs any changes; hence my question.

public async Task<List<MorthoImplantInformationMorthoImplantLookupTableDto>> GetAllMorthoImplantForTableDropdown() { return await _lookup_morthoImplantRepository.GetAll() .Select(morthoImplant => new MorthoImplantInformationMorthoImplantLookupTableDto { Id = morthoImplant.Id, DisplayName = morthoImplant == null || morthoImplant.ImplantCreator == null ? "" : morthoImplant.ImplantCreator.ToString().Substring(0,10) + " " + morthoImplant.ImplantModel.ToString().Substring(0,10) }).ToListAsync(); }

The complete error is below but I am puzzled why this happens since the data seems OK, I am 'just' appending another field

    System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')     at System.String.Substring(Int32 startIndex, Int32 length)     at lambda_method2489(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator )     at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()     at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)     at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)     at MedicineInfoTechnlgy.Mortho.NsMorthoImplantInformation.MorthoImplantInformationsAppService.GetAllMorthoImplantForTableDropdown() in C:\Github\murphymj5209\MedicineInfoTechnlgy.Mortho\aspnet-core\src\MedicineInfoTechnlgy.Mortho.Application\NsMorthoImplantInformation\MorthoImplantInformationsAppService.cs:line 245     at lambda_method2480(Closure , Object )     at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

1 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Hi murphymj5209, This is because the length of morthoImplant.ImplantModel.ToString(). is less than 10, so the above exception is prompted.