OpenGlot / OpenGlot.API

C# API for OpenGlot
MIT License
0 stars 0 forks source link

500 Internal Server Error When Retrieving Course by ID #1

Open evelyn-2022 opened 2 months ago

evelyn-2022 commented 2 months ago

Description: I encountered a 500 Internal Server Error when trying to retrieve a specific course by its ID using the API. The request was made to the following endpoint: https://localhost:443/api/Courses/1

Steps to Reproduce:

  1. Start the server with docker-compose up.
  2. Make a GET request to https://localhost:443/api/Courses/1.
  3. Observe the 500 Internal Server Error response.

Server Logs: api-1 | Request Method: GET api-1 | Request Path: /api/Courses/1 api-1 | Request Headers: Accept: /, Connection: close, Host: localhost, User-Agent: PostmanRuntime/7.39.0, Accept-Encoding: gzip, deflate, br, X-Real-IP: 192.168.65.1, X-Forwarded-For: 192.168.65.1, X-Forwarded-Proto: https, Postman-Token: ec05bfb4-04e1-4525-835b-fc65bf69573b api-1 | Request Body: api-1 | info: PolyglotAPI.Controllers.CoursesController[0] api-1 | Getting course with ID: 1 api-1 | info: Microsoft.EntityFrameworkCore.Database.Command[20101] api-1 | Executed DbCommand (7ms) [Parameters=[@id_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30'] api-1 | SELECT t."Id", t."LanguageId", t."Title", m."Id", m."CourseId", m."Title" api-1 | FROM ( api-1 | SELECT c."Id", c."LanguageId", c."Title" api-1 | FROM "Courses" AS c api-1 | WHERE c."Id" = @__id_0 api-1 | LIMIT 1 api-1 | ) AS t api-1 | LEFT JOIN "Modules" AS m ON t."Id" = m."CourseId" api-1 | ORDER BY t."Id" api-1 | fail: Microsoft.AspNetCore.Server.Kestrel[13] reverse-proxy-1 | 192.168.65.1 - - [17/Jun/2024:15:45:54 +0000] "GET /api/Courses/1 HTTP/1.1" 500 0 "-" "PostmanRuntime/7.39.0" "-" api-1 | Connection id "0HN4ESFQ5N47T", Request id "0HN4ESFQ5N47T:00000001": An unhandled exception was thrown by the application. api-1 | System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[PolyglotAPI.Data.Models.Course,PolyglotAPI.Data.Repos.CourseRepository+d3]' is invalid for serialization or deserialization because it is a pointer type, is a ref struct, or contains generic parameters that have not been replaced by specific types. api-1 | at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_CannotSerializeInvalidType(Type typeToConvert, Type declaringType, MemberInfo memberInfo) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreatePropertyInfo(JsonTypeInfo typeInfo, Type typeToConvert, MemberInfo memberInfo, JsonSerializerOptions options, Boolean shouldCheckForRequiredKeyword, Boolean hasJsonIncludeAttribute) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean constructorHasSetsRequiredMembersAttribute, PropertyHierarchyResolutionState& state) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options) api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type) api-1 | at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) api-1 | --- End of stack trace from previous location --- api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type) api-1 | at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() api-1 | --- End of stack trace from previous location --- api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) api-1 | at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) api-1 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) api-1 | at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) api-1 | at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) api-1 | at Startup.<>c.<<Configure>b__8_0>d.MoveNext() in /src/Startup.cs:line 147 api-1 | --- End of stack trace from previous location --- api-1 | at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

evelyn-2022 commented 2 months ago

500Internal Server Error When Retrieving All Modules

Description

I encountered a 500 Internal Server Error when trying to retrieve all modules. The request was made to the endpoint https://localhost:443/api/Modules

Steps to Reproduce

Make a GET request to https://localhost:443/api/Modules.

Server logs

api-1 | Request Method: GET api-1 | Request Path: /api/Modules api-1 | Request Headers: Accept: /, Connection: close, Host: localhost, User-Agent: PostmanRuntime/7.39.0, Accept-Encoding: gzip, deflate, br, X-Real-IP: 192.168.65.1, X-Forwarded-For: 192.168.65.1, X-Forwarded-Proto: https, Postman-Token: b945d0bb-3cd6-4af9-b8e9-1684261f7668 api-1 | Request Body: api-1 | info: PolyglotAPI.Controllers.ModulesController[0] api-1 | Getting all modules api-1 | info: Microsoft.EntityFrameworkCore.Database.Command[20101] api-1 | Executed DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] api-1 | SELECT m."Id", m."CourseId", m."Title" api-1 | FROM "Modules" AS m api-1 | fail: Microsoft.AspNetCore.Server.Kestrel[13] api-1 | Connection id "0HN4GAVQN2C1N", Request id "0HN4GAVQN2C1N:00000001": An unhandled exception was thrown by the application. api-1 | System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[System.Collections.Generic.IEnumerable1[PolyglotAPI.Data.Models.Module],PolyglotAPI.Data.Repos.ModuleRepository+<GetAllAsync>d__2]' is invalid for serialization or deserialization because it is a pointer type, is a ref struct, or contains generic parameters that have not been replaced by specific types. api-1 | at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_CannotSerializeInvalidType(Type typeToConvert, Type declaringType, MemberInfo memberInfo) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreatePropertyInfo(JsonTypeInfo typeInfo, Type typeToConvert, MemberInfo memberInfo, JsonSerializerOptions options, Boolean shouldCheckForRequiredKeyword, Boolean hasJsonIncludeAttribute) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean constructorHasSetsRequiredMembersAttribute, PropertyHierarchyResolutionState& state) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options) api-1 | at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options) api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type) api-1 | at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) api-1 | --- End of stack trace from previous location --- api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) api-1 | at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type) api-1 | at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() api-1 | --- End of stack trace from previous location --- api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) api-1 | at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) api-1 | at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) api-1 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) api-1 | at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) api-1 | at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) api-1 | at Startup.<>c.<b__8_0>d.MoveNext() in /src/Startup.cs:line 147 api-1 | --- End of stack trace from previous location --- api-1 | at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application) reverse-proxy-1 | 192.168.65.1 - - [19/Jun/2024:12:07:18 +0000] "GET /api/Modules HTTP/1.1" 500 0 "-" "PostmanRuntime/7.39.0" "-"