0

I'm working on adding propagation to HotChocolate GraphQL server but simply can't get it working.

I've configured my propagation in my ConfigureServices services.AddHeaderPropagation(o => o.Headers.Add("Authorization"));

I've added it to my httpClient: services.AddHttpClient(AssumptionManagement, c => c.BaseAddress = new Uri("http://localhost:19801")).AddHeaderPropagation();

I've added it in my Configure method: app.UseHeaderPropagation();

Despite all this it still gives me the following error when I run the app in debug:

An unhandled exception of type System.InvalidOperationException occurred in System.Private.CoreLib.dll: The HeaderPropagationValues.Headers property has not been initialized. 

Register the header propagation middleware by adding app.UseHeaderPropagation() in the Configure(...) method. Header propagation can only be used within the context of an HTTP request.'

Am I just not seeing something here or what am I doing wrong?

Frankich
  • 842
  • 9
  • 19
  • 1
    Is the `Microsoft.AspNetCore.HeaderPropagation` nuget package installed? – yohosuff Dec 29 '21 at 19:55
  • Also, check where `app.UseHeaderPropagation();` is called. I put it after `app.UseStaticFiles();` and before `app.UseRouting();` as shown here: https://thecodeblogger.com/2021/05/25/request-header-propagation-in-net-core-web-applications/. – yohosuff Dec 29 '21 at 19:58
  • Did you ever resolve this - I have the same problem – tappetyclick Jul 28 '22 at 12:21
  • Are you using `InitializeOnStartup`? I ran into this same scenario and after disabling `InitializeOnStartup` this issue went away. I'm still looking into _why_. My guess is that the warm up is using the services config, but not the middleware. – walexnelson Nov 14 '22 at 04:31
  • 2
    was it because of the source of the request being from a middleware instead of controller? – Nathan Feb 07 '23 at 23:56
  • 1
    @Nathan That is the issue I am facing. header propagation works fine everywhere unless the httpClient in question is called from my auth middleware - do you have any suggestsions ? – Bassie Jun 13 '23 at 10:35

0 Answers0