NullReferenceException after calling HttpRequest.GetResponse()

0 votes
asked Aug 5 by mobile653 (260 points)

Using the Rebex HTTPS library version 2018R4 on .NET Compact Framework 3.5 we got some NullReferenceExceptions with the following Stack:

System.NullReferenceException: NullReferenceException
at Rebex.Net.HttpRequest.edna()
at Rebex.Net.HttpRequest.edmz()
at Rebex.Net.HttpRequest.GetResponse()
at [our code]

This should not happen, right?
Could this be already fixed in a later version? (Can’t find anything about this in your release notes.)


2 Answers

0 votes
answered Aug 5 by Lukas Pokorny (100,910 points)

Yes, this should not happen, at least unless you call multiple methods or properties of a single HttpRequest instance from multiple threads at the same time. See more information on .NET's WebRequest that applies to HttpRequest as well.

Please check your application and let us know whether this could be the reason or not.

If you don't call multiple methods or properties on a single HttpRequest instance (at the same time), a NullReferenceException should never occur in GetResponse method, so this exception would indicate a yet-unknown bug in Rebex HTTPS (which we would aim to fix as soon as possible).

0 votes
answered 10 hours ago by mobile653 (260 points)

We have examined our code and found no evidence of a multiple usage of a HttpRequest instance. The object is created using

var request = (HttpRequest)WebRequest.Create(URL);

and the command leading to the Exception

var response = (HttpResponse)request.GetResponse();

is only called once. The finally block looks like this:

} finally {
    if (request != null) {
    request = null;

Maybe we have created multiple HttpRequest instances with the same URL in parallel, but those ones should not interfere, right?