This is a migrated thread and some comments may be shown as answers.

HeaderCollection Key Already Added: Cache-Control

9 Answers 600 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 03 Mar 2020, 09:01 PM

I'm trying to set things up for the first time in a .Net Core ASP 3.1 Application.

My ReportsController appears to be recognized properly (the constructor is called with the IReportServiceConfiguration) and the client attempts to call:

 

api/reports/resources/js/telerikReportViewer (with a ?_=<number> on the end)

 

But i'm getting this error:

"Message": "An error has occurred.","ExceptionMessage": "An item with the same key has already been added. Key: Cache-Control"

 

Full:

{

"Message": "An error has occurred.","ExceptionMessage": "An item with the same key has already been added. Key: Cache-Control","ExceptionType": "System.ArgumentException","StackTrace": " at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\r\n at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)\r\n at Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.Add(String key, StringValues value)\r\n at Telerik.Reporting.Services.AspNetCore.ReportsControllerBase.GetResourceCore(String folder, String resourceName, Type type)\r\n at Telerik.Reporting.Services.AspNetCore.ReportsControllerBase.GetResource(String folder, String resourceName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"

}

9 Answers, 1 is accepted

Sort by
0
Ben
Top achievements
Rank 1
answered on 03 Mar 2020, 09:17 PM
Note that calling "/api/reports/formats" does succeed.
0
Ivan Hristov
Telerik team
answered on 06 Mar 2020, 03:48 PM

Hello Ben,

I provided an answer in the support ticket #1456298. Since the cause of the issue is not yet determined, I will not paste here my answer. As soon as we are sure what the problem is, I will update the current forum thread so it will be useful for all the developers that might hit the same problem.

Regards,
Ivan Hristov
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Christian
Top achievements
Rank 1
Iron
answered on 13 May 2020, 01:58 PM

Hi,

I had the same error reason but not the same error message, only when we tried to display a report.

This is the error:

{
"message":"An error has occurred.",
"exceptionMessage":"An item with the same key has already been added.",
"exceptionType":"System.ArgumentException","stackTrace":"   at
  Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowDuplicateKeyException()\r\n   at
  Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.System.Collections.Generic.IDictionary<System.String,Microsoft.Extensions.Primitives.StringValues>.Add(String key, StringValues value)\r\n   at
  Telerik.Reporting.Services.AspNetCore.ReportsControllerBase.GetResourceCore(String folder, String resourceName, Type type)\r\n   at
  Telerik.Reporting.Services.AspNetCore.ReportsControllerBase.GetResource(String folder, String resourceName)\r\n   at
  lambda_method(Closure , Object , Object[] )\r\n   at
  Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n   at
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()"
}

 

In our code I found a line where we added the "Cache-Control" header on application startup:

context.Response.Headers.Append("Cache-Control", "no-cache");

 

The error seems to be that the Telerik Reporting also tries to add the same response header. When it exists the error occures. After removing our line everything works fine.

@Ben

It may help only to add the header if it still does not exist!?

if (!context.Response.Headers.ContainsKey("Cache-Control")) { add header ... }
0
Christian
Top achievements
Rank 1
Iron
answered on 13 May 2020, 02:03 PM
Sorry, I wanted to suggest it to Ivan Hristov.
0
Ben
Top achievements
Rank 1
answered on 13 May 2020, 02:03 PM
@Christian unfortunately in my situation the header was being added by a Microsoft library that I had no control over the headers that got added.  Telerik actually fixed this internally and released a patch so you might try updating to the latest version.
0
Christian
Top achievements
Rank 1
Iron
answered on 13 May 2020, 02:12 PM

Hi Ben,

thanks for your fast reply and info that the error has been fixed. Great.

So the fix must be in Version 14.1.20.513 cause I am using the previous unpatched version 14.0.20.219 right now. I'll try the patch next time.

0
Ivan Hristov
Telerik team
answered on 14 May 2020, 11:28 AM

Hi all,

Just wanted to confirm that the issue with the Cache-Control key is fixed in internal build 14.0.20.325. Of course, the fix is also included in the R2 2020, which was released yesterday. You're more than welcome to download it, give it a try and share your thoughts.

Regards,
Ivan Hristov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Christian
Top achievements
Rank 1
Iron
answered on 14 May 2020, 01:37 PM

Hello Ivan,

yes, I can also confirm that the issue is fixed now, thank you. We just updated to 14.1.20.513 today.

Regards!

0
Ivan Hristov
Telerik team
answered on 18 May 2020, 04:34 PM

Hello Christian,

Thanks for confirming that the fix works in your scenario.

Regards,
Ivan Hristov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
General Discussions
Asked by
Ben
Top achievements
Rank 1
Answers by
Ben
Top achievements
Rank 1
Ivan Hristov
Telerik team
Christian
Top achievements
Rank 1
Iron
Share this question
or