I have azure function deployed on .Net 8.0 and it contains a slightly longer running code than usual of about 3-4 minutes on average. My issue is the code executes completely and stores the data to azure storage which is it’s final step. I can also see in logs the final step which marks “processing ends”. However right after when I am sending HttpResponse with OkObjectResult. I have an error like below.
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Function ‘TestFunction’, Invocation id ‘7d25ae02-bf21-4aed-b2a8-b9bd97536f5e’: An exception was thrown by the invocation.
Exception: System.ObjectDisposedException: Request has finished and HttpContext disposed.
Object name: ‘HttpContext’.
at Microsoft.AspNetCore.Http.DefaultHttpContext.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Features()
at Microsoft.AspNetCore.Routing.RoutingHttpContextExtensions.GetRouteData(HttpContext httpContext)
at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:a_work1sextensionsWorker.Extensions.Http.AspNetCoresrcFunctionsMiddlewareFunctionsHttpProxyingMiddleware.cs:line 54
at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:a_work1ssrcDotNetWorker.CoreFunctionsApplication.cs:line 77
Stack: at Microsoft.AspNetCore.Http.DefaultHttpContext.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Features()
at Microsoft.AspNetCore.Routing.RoutingHttpContextExtensions.GetRouteData(HttpContext httpContext)
at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:a_work1sextensionsWorker.Extensions.Http.AspNetCoresrcFunctionsMiddlewareFunctionsHttpProxyingMiddleware.cs:line 54
at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:a_work1ssrcDotNetWorker.CoreFunctionsApplication.cs:line 77
I have no idea what is causing this. Does anyone know or have come across this or if it’s unexpected behaviour with .net 8 functions ?