Comments (11)
We found a workaround for this that may work for others. It involves a very minimal custom middleware component:
public class HttpContextAccessorMiddleware(IHttpContextAccessor httpContextAccessor) : IFunctionsWorkerMiddleware
{
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
{
httpContextAccessor.HttpContext = context.GetHttpContext();
await next(context);
}
}
Then wire it up in Program.cs
var host = new HostBuilder()
.ConfigureFunctionsWebApplication(builder =>
{
builder.UseMiddleware<HttpContextAccessorMiddleware>();
})
This should allow you to inject IHttpContextAccessor as you did prior to moving to isolated. I have only confirmed this on .NET 6, but I assume it will work in 8 as well.
from azure-functions-dotnet-worker.
We are using the above middleware pattern in our .net8 out-of-process functions. However it does not appear to be 100% parity with in-proc.
I'm doing the following to get access to Application Insights request telemetry so that we can insert custom properties. HttpContext
is available but this returns NULL still.
var telemetry = _httpContextAccessor.HttpContext?.Features.Get<RequestTelemetry>();
I'm aware that this isn't quite on point; just be aware that the above middleware suggestion may not solve everything.
from azure-functions-dotnet-worker.
Yes this works with the middleware in .NET 8
from azure-functions-dotnet-worker.
Came across same issue, after migrating from .net 6 to .net 8 the IHttpContextAccessor is null when retrieved from context.
from azure-functions-dotnet-worker.
I am also facing the same issue when I am trying to upgrade my projects from Net6 to Net8.
I can initialize HttpContextAccessor by using services.AddHttpContextAccessor()
But then HttpContextAccessor.HttpContext is null.
Any idea when this issue is going to be fixed?
Note: We didn't need to initialize HttpContextAccessor in Net6. It is automatically getting initialized during each function endpoint call.
from azure-functions-dotnet-worker.
Same issue like @Tech-Sohail just described, here also :(
As far as I understand, the problem is that I am not using an HTTPTrigger. If you are using an Event trigger or a Timer trigger, you won't have a context... IHttpContextAccessor and HttpContext are not available in these cases. It seems the idea is that if you have information in the context, that info should be in the event itself.
from azure-functions-dotnet-worker.
Same issue like @Tech-Sohail just described, here also :(
As far as I understand, the problem is that I am not using an HTTPTrigger. If you are using an Event trigger or a Timer trigger, you won't have a context... IHttpContextAccessor and HttpContext are not available in these cases. It seems the idea is that if you have information in the context, that info should be in the event itself.
No, this issue is purely about the lack of HTTP Context on a http trigger, I would never expect to have a http trigger on event or Timer, in .NET 6 we uses Queue triggers extensively but there is no http context in those circumstances and that is expected behaviour.
Still waiting on anything from MS on this, so far seems to just have been added and removed from various labels, I rechecked the latest nuget packages recently (see sample project) and its still ongoing to latest releases
from azure-functions-dotnet-worker.
@MarkMilfordMe I don't think that this is a .NET 8 vs .NET 6 issue. It appears to be an in-process vs out-of-process function issue. Your .NET 6 demo project is in-process and your .NET 8 demo project is out-of-process. If you were to change your .NET 6 project to out-of-process, I suspect you would see the same behavior. We are currently seeing the same thing when doing a straight in-process to out-of-process migration in a .NET 6 function application.
from azure-functions-dotnet-worker.
@MarkMilfordMe I don't think that this is a .NET 8 vs .NET 6 issue. It appears to be an in-process vs out-of-process function issue. Your .NET 6 demo project is in-process and your .NET 8 demo project is out-of-process. If you were to change your .NET 6 project to out-of-process, I suspect you would see the same behavior. We are currently seeing the same thing when doing a straight in-process to out-of-process migration in a .NET 6 function application.
Thanks, I'll try that, guess still means we can't update to .NET 8 though, as .NET 8 doesn't support in-process to my knowledge.
from azure-functions-dotnet-worker.
@MarkMilfordMe I don't think that this is a .NET 8 vs .NET 6 issue. It appears to be an in-process vs out-of-process function issue. Your .NET 6 demo project is in-process and your .NET 8 demo project is out-of-process. If you were to change your .NET 6 project to out-of-process, I suspect you would see the same behavior. We are currently seeing the same thing when doing a straight in-process to out-of-process migration in a .NET 6 function application.
Thanks, I'll try that, guess still means we can't update to .NET 8 though, as .NET 8 doesn't support in-process to my knowledge.
You are correct. .NET 8 is not supported for in-proc functions yet. There is a tracking issue that indicates that support for Windows functions should be rolling out sometime this month (June).
from azure-functions-dotnet-worker.
@MarkMilfordMe I don't think that this is a .NET 8 vs .NET 6 issue. It appears to be an in-process vs out-of-process function issue. Your .NET 6 demo project is in-process and your .NET 8 demo project is out-of-process. If you were to change your .NET 6 project to out-of-process, I suspect you would see the same behavior. We are currently seeing the same thing when doing a straight in-process to out-of-process migration in a .NET 6 function application.
Thanks, I'll try that, guess still means we can't update to .NET 8 though, as .NET 8 doesn't support in-process to my knowledge.
You are correct. .NET 8 is not supported for in-proc functions yet. There is a tracking issue that indicates that support for Windows functions should be rolling out sometime this month (June).
So just did a quick example (added to original repo) and yes it fails on .net 6 out of proc. Will cross fingers that In-Proc .NET 8 rolls out in plenty of time for us to transistion before november when .net 6 is out of support! Will subscribe to the issue you mentioned. Thanks
from azure-functions-dotnet-worker.
Related Issues (20)
- Graceful shutdown of a QueueTrigger function via observing the CancellationToken HOT 2
- HTTP body conversion will throw an InvalidOperationException when the request have an empty body
- [1ES] Investigate dotnet-host.public pipeline windows artifact build issue
- [1ES] Remove `_manifest` folder from FunctionsNetHost nuget payload
- CORS error in Azure Func with Linux Flex Consumption HOT 6
- Inheriting FunctionAttribute not supported? HOT 4
- Error: 'Having multiple overloads of method 'Configure' is not supported.' after upgrading .NET 6.0 to .NET 8.0 using Upgrade Assistant HOT 1
- HttpTrigger GET parameters not mapped to custom class in .NET 8 and isolated HOT 1
- .NET 8 Isolated Logging to Application Insights I can't change LogLevel from Azure Environment Variables
- .NET 8 Isolated function do not startup on Azure environment HOT 2
- Is it possible to disable automatic abandoning of service bus messages? HOT 4
- Kafka Trigger Avro Deserialization for isolated model
- Replacement for ILifeCycleNotificationHelper in Isolated Worker Process
- IFunctionBindingsFeature is internal and pevent unit testing in middleware
- ExtensionStartupRunnerGenerator generating code which conflicts with customer code (namespace)
- Update to Microsoft.Azure.Functions.Worker.Core version 1.18 breaks Open Telemetry Tracing for .net8 isolated function
- Azure function with QueueTrigger fails to pass whitesource scan (Azure Identity Libraries and Microsoft Authentication Library Elevation of Privilege Vulnerability)) HOT 2
- CosmosDBInput returning 500 instead of 404 when item does not exist
- ServiceBusOutput does not support byte[] as claimed HOT 1
- Add support to clear Service Bus session state
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-functions-dotnet-worker.