Dependency Injection Test Failed on 'There is no HTTP context,'

I recently attempted to upgrade from ComponentSpace version 4.6.0 to version 4.9.0, and I’ve encountered an issue with one of my unit tests.

In this unit test, I’m verifying if all dependencies that will be injected can be resolved successfully. Unfortunately, the test is failing, and the specific issue is related to the ‘ComponentSpace.Saml2.Bindings.IHttpRequest’ and ‘ComponentSpace.Saml2.Bindings.IHttpResponse’ not being resolved correctly.

Upon investigating the error message, I came across the following message: “There is no HTTP context.”

Using ILSpy to examine the DLL code, I noticed a change in the default behavior of ‘ComponentSpace.Saml2.Bindings.AspNetHttpResponse’ and ‘ComponentSpace.Saml2.Bindings.AspNetHttpRequest’ compared to version 4.6.0.

Here’s what I found in the constructor:
‘’‘csharp
if (httpContextAccessor.HttpContext == null)
{
throw new SamlBindingException(“There is no HTTP context.”);
}
’‘’
It seems that in version 4.9.0, the presence of the ‘HttpContext’ is required.

My question is: Was this change in behavior expected? I couldn’t find any information about it in the release notes. If anyone has insights or suggestions on how to handle this change during unit testing or can point me to relevant release notes, I would greatly appreciate it.

Thank you in advance for your assistance!

We had a customer run into an unusual scenario where there was no HttpContext. This prompted us to add the check and throw a specific exception.

It wasn’t documented in the release notes as it was considered a minor change that shouldn’t impact most customers.

The AspNetHttpRequest and AspNetHttpResponse classes are dependent on an HttpContext to access the HTTP request and response objects.