Hello, On Asp.net 9 Zero, when I return my objects, "return new PagedResultDto<GetControleEAForViewDto>( totalCount, results );"
I get error 500. If I test it on an Asp.net 8 Zero platform, it works correctly. And in debug mode, when I hover over it, my data is displayed, but on Swagger, it doesn't display, and it gives me error 500. Do you have any ideas? Thanks.
4 Answer(s)
-
0
Hi @gtc
Thank you for reporting this issue. Since you mentioned that the same code works on ASP.NET Zero v8 but returns error 500 on v9, this looks like it may be related to a breaking change or a serialization difference between the versions.
To help us investigate further, could you please provide the following details:
- The exact ASP.NET Zero version you are using on v9.
- The full exception details stack trace from your server logs (the 500 error in Swagger usually hides the real cause).
- The code of your
GetControleEAForViewDtoclass (or at least its properties). Sometimes circular references or unsupported property types can cause serialization errors.
In many cases, error 500 in Swagger while data is visible in debug mode points to a JSON serialization problem (e.g., reference loops, unsupported property types, or large data structures). Once we have the stack trace, we can confirm whether this is the case.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi, thank you for your feedback 1/ version ASP.NET CORE & Angular .NET 9.0 v14.1.0 2/ log : INFO 2025-09-24 16:00:34,447 [20 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/2 GET https://localhost:44301/api/services/app/ControleEAs/GetAll - - - INFO 2025-09-24 16:00:34,450 [20 ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Portail_GTC.EA.ControleEAsAppService.GetAll (Portail_GTC.Application)' INFO 2025-09-24 16:00:34,466 [20 ] c.Infrastructure.ControllerActionInvoker - Route matched with {area = "app", action = "GetAll", controller = "ControleEAs"}. Executing controller action with signature System.Threading.Tasks.Task
1[Abp.Application.Services.Dto.PagedResultDto1[Portail_GTC.EA.Dtos.GetControleEAForViewDto]] GetAll(Portail_GTC.EA.Dtos.GetAllControleEAsInput) on controller Portail_GTC.EA.ControleEAsAppService (Portail_GTC.Application). ERROR 2025-09-24 16:00:47,908 [19 ] Microsoft.EntityFrameworkCore.Update - An exception occurred in the database while saving changes for context type 'Portail_GTC.EA.EA_ProdbContext'. System.InvalidOperationException: The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit. at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.OnFirstExecution() at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) System.InvalidOperationException: The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit. at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.OnFirstExecution() at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) ERROR 2025-09-24 16:00:48,452 [19 ] Mvc.ExceptionHandling.AbpExceptionFilter - The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit. System.InvalidOperationException: The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit. at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.OnFirstExecution() at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Abp.EntityFrameworkCore.AbpDbContext.SaveChangesAsync(CancellationToken cancellationToken) at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChangesAsync() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CompleteUowAsync() at Abp.Domain.Uow.UnitOfWorkBase.CompleteAsync() at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) INFO 2025-09-24 16:00:48,574 [19 ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'. INFO 2025-09-24 16:00:48,579 [19 ] c.Infrastructure.ControllerActionInvoker - Executed action Portail_GTC.EA.ControleEAsAppService.GetAll (Portail_GTC.Application) in 14113.2001ms INFO 2025-09-24 16:00:48,580 [19 ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Portail_GTC.EA.ControleEAsAppService.GetAll (Portail_GTC.Application)' INFO 2025-09-24 16:00:48,583 [19 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/2 GET https://localhost:44301/api/services/app/ControleEAs/GetAll - 500 - application/json;+charset=utf-8 14134.4313ms3/ I don't think it's due to the JSON format. I tried a simple method and no problem.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Additional information. I am running the stored procedure in a second DB context connected to another database.
code source repository :
using Abp.Data; using Abp.Domain.Repositories; using Abp.Domain.Uow; using Abp.EntityFrameworkCore; using Abp.MultiTenancy; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Portail_GTC.EA; using Portail_GTC.EA.entity; using Portail_GTC.EA.Repository; using Portail_GTC.EntityFrameworkCore.Repositories; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Threading.Tasks;
namespace Portail_GTC.Repository { public class RepositoryControleEA : EA_ProdRepositoryBase<ControleEA>, IRepositoryControleEA { private readonly IActiveTransactionProvider _transactionProvider; private readonly IUnitOfWorkManager _unitOfWorkManager;
public RepositoryControleEA( IDbContextProvider<EA_ProdbContext> dbContextProvider, IActiveTransactionProvider transactionProvider, IUnitOfWorkManager unitOfWorkManager) : base(dbContextProvider) { _transactionProvider = transactionProvider; _unitOfWorkManager = unitOfWorkManager; } /// <summary> /// Exécute la procédure stockée wb_ControlesRT02 et retourne les résultats. /// </summary> public async Task<List<ControleEA>> GetAllControleEAAsync() { var result = new List<ControleEA>(); // Récupère la connexion et la transaction EF Core var connection = GetContext().Database.GetDbConnection(); var transaction = GetActiveTransaction(); using (var command = connection.CreateCommand()) { command.CommandText = "wb_ControlesRT02"; command.CommandType = CommandType.StoredProcedure; command.Transaction = transaction; // Ajout des paramètres command.Parameters.Add(new SqlParameter("@Exploitant", -1)); command.Parameters.Add(new SqlParameter("@Constructeur", -1)); command.Parameters.Add(new SqlParameter("@NumLot", DBNull.Value)); command.Parameters.Add(new SqlParameter("@NumExploitant", DBNull.Value)); command.Parameters.Add(new SqlParameter("@NumConstructeur", DBNull.Value)); command.Parameters.Add(new SqlParameter("@Nomclient", DBNull.Value)); command.Parameters.Add(new SqlParameter("@CP", DBNull.Value)); command.Parameters.Add(new SqlParameter("@Prestataire", -1)); command.Parameters.Add(new SqlParameter("@Debut", new DateTime(2023, 12, 31))); command.Parameters.Add(new SqlParameter("@Fin", new DateTime(2024, 12, 31))); command.Parameters.Add(new SqlParameter("@Classe", DBNull.Value)); command.Parameters.Add(new SqlParameter("@Approuve", 1)); command.Parameters.Add(new SqlParameter("@DateAllSearch", 3)); // EF Core ouvre automatiquement la connexion si nécessaire if (connection.State != ConnectionState.Open) await connection.OpenAsync(); using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { result.Add(MapControleEA(reader)); } } } return result; } /// <summary> /// Map un DbDataReader vers l'entité ControleEA /// </summary> private ControleEA MapControleEA(DbDataReader reader) { return new ControleEA { IdOrdreMission = Convert.ToInt64(reader["IdOrdreMission"]), Constructeur = reader["Constructeur"]?.ToString(), NumExploitant = reader["NumExploitant"]?.ToString(), NumeroLot = reader["NumeroLot"]?.ToString(), NumClient = reader["NumClient"]?.ToString(), NomClient = reader["NomClient"]?.ToString(), CodePostal = reader["CodePostal"]?.ToString(), Exploitant = reader["Exploitant"]?.ToString(), Prestataire = reader["Prestataire"]?.ToString(), DateDeControle = (DateTime)(reader["DateDeControle"] != DBNull.Value ? Convert.ToDateTime(reader["DateDeControle"]) : (DateTime?)null), // DateDeControle = reader["DateDeControle"] != DBNull.Value ? Convert.ToDateTime(reader["DateDeControle"]) : (DateTime?)null, DateApprobation = reader["DateApprobation"]?.ToString() }; } /// <summary> /// Retourne la transaction active pour le DbCommand /// </summary> private DbTransaction GetActiveTransaction() { return (DbTransaction)_transactionProvider.GetActiveTransaction(new ActiveTransactionProviderArgs { {"ContextType", typeof(EA_ProdbContext) }, {"MultiTenancySide", MultiTenancySide } }); } }}
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
--------------------------------------------------------------------------------------------------------------------------------------- code source service
public virtual async Task<PagedResultDto<GetControleEAForViewDto>> GetAll(GetAllControleEAsInput input) { var AllControleEA = await _repositoryControleEA.GetAllControleEAAsync(); var filteredControleEA = AllControleEA .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Constructeur.Contains(input.Filter) || e.NumExploitant.Contains(input.Filter) || e.NumeroLot.Contains(input.Filter) || e.NumClient.Contains(input.Filter) || e.NomClient.Contains(input.Filter) || e.CodePostal.Contains(input.Filter) || e.Exploitant.Contains(input.Filter) || e.Prestataire.Contains(input.Filter) || e.DateApprobation.Contains(input.Filter)) .WhereIf(input.MinIdOrdreMissionFilter != null, e => e.IdOrdreMission >= input.MinIdOrdreMissionFilter) .WhereIf(input.MaxIdOrdreMissionFilter != null, e => e.IdOrdreMission <= input.MaxIdOrdreMissionFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.ConstructeurFilter), e => e.Constructeur.ToLower().Contains(input.ConstructeurFilter.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(input.NumExploitantFilter), e => e.NumExploitant.ToLower().Contains(input.NumExploitantFilter.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(input.NumeroLotFilter), e => e.NumeroLot.ToLower().Contains(input.NumeroLotFilter.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(input.NumClientFilter), e => e.NumClient.ToLower().Contains(input.NumClientFilter)) .WhereIf(!string.IsNullOrWhiteSpace(input.NomClientFilter), e => e.NomClient.ToLower().Contains(input.NomClientFilter)) .WhereIf(!string.IsNullOrWhiteSpace(input.CodePostalFilter), e => e.CodePostal.ToLower().Contains(input.CodePostalFilter)) .WhereIf(!string.IsNullOrWhiteSpace(input.ExploitantFilter), e => e.Exploitant.ToLower().Contains(input.ExploitantFilter)) .WhereIf(!string.IsNullOrWhiteSpace(input.PrestataireFilter), e => e.Prestataire.ToLower().Contains(input.PrestataireFilter)) .WhereIf(input.MinDateDeControleFilter != null, e => e.DateDeControle >= input.MinDateDeControleFilter) .WhereIf(input.MaxDateDeControleFilter != null, e => e.DateDeControle <= input.MaxDateDeControleFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.DateApprobationFilter), e => e.DateApprobation.Contains(input.DateApprobationFilter)); //var pagedAndFilteredControleEAs = filteredControleEA // .OrderBy(input.Sorting ?? "id asc") // .PageBy(input); var pagedAndFilteredTestcontroleEAs = filteredControleEA.AsQueryable() .OrderBy(input.Sorting ?? "id asc") .PageBy(input); var controleEAs = from o in pagedAndFilteredTestcontroleEAs select new { o.IdOrdreMission, o.Constructeur, o.NumeroLot, o.NumExploitant, o.NumClient, o.CodePostal, o.NomClient, o.Exploitant, o.Prestataire, o.DateDeControle, o.DateApprobation, Id = o.Id }; // var totalCount = await filteredControleEA.CountAsync(); var totalCount = filteredControleEA.Count(); var dbList = controleEAs.ToList(); //var dbList = controleEAs.ToList(); var results = new List<GetControleEAForViewDto>(); foreach (var o in dbList) { var res = new GetControleEAForViewDto() { ControleEA = new ControleEADto { IdOrdreMission = o.IdOrdreMission, Constructeur = o.Constructeur, NumeroLot = o.NumeroLot, NumExploitant = o.NumExploitant, NumClient = o.NumClient, CodePostal = o.CodePostal, NomClient = o.NomClient, Exploitant = o.Exploitant, Prestataire = o.Prestataire, DateDeControle = o.DateDeControle, DateApprobation = o.DateApprobation, Id = o.Id, } }; results.Add(res); } return new PagedResultDto<GetControleEAForViewDto>( totalCount, results ); }
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)