Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException for CorrelationId when targeting .NET Framework #37

Open
LucaMahler opened this issue Jun 17, 2024 · 1 comment
Assignees

Comments

@LucaMahler
Copy link

LucaMahler commented Jun 17, 2024

When using the CorrelationIdEnricher and targeting .NET framework, a NullReferenceException will occur here:
var header = httpContext.Request.Headers[_headerKey].ToString();

Because httpContext.Request.Headers[_headerKey] is actually null. The next line is:

   var correlationId = !string.IsNullOrWhiteSpace(header)
       ? header
       : (_addValueIfHeaderAbsence ? Guid.NewGuid().ToString() : null);

This is a bit strange. You should call .ToString() after the null check, don't you?

@mo-esmp mo-esmp self-assigned this Jun 27, 2024
@mo-esmp
Copy link
Member

mo-esmp commented Jun 28, 2024

This code works fine in .NET Core and unfortunately, there is no way that I can implement unit tests for enrichers when the target framework is .NET Framework and the reason is that HttpCaontext.Current is a static class and mocking it is extremely hard. For the next release, I will drop support for .NET Framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants