-
Notifications
You must be signed in to change notification settings - Fork 87
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
If HttpResponseMessage is disposed next request fails #33
Comments
Can you provide a reproducible example? The following succeeds for me: var mockHttp = new MockHttpMessageHandler();
var mockedRequest = mockHttp.When("/path");
mockedRequest.Respond(req => new StringContent("test", Encoding.UTF8, "text/plain"));
var request = new HttpRequestMessage(HttpMethod.Post, "http://www.tempuri.org/path?apple=red&pear=green")
{
Content = new StringContent("testing")
};
string contentA;
using (var responseA = mockedRequest.SendAsync(request, CancellationToken.None).Result)
{
contentA = responseA.Content.ReadAsStringAsync().Result;
}
string contentB;
using (var responseB = mockedRequest.SendAsync(request, CancellationToken.None).Result)
{
contentB = responseB.Content.ReadAsStringAsync().Result;
} |
Hi there, I haven't heard back from you on this issue for a while so I'm going to close it. Please feel free to create a new issue if you manage to create a reproducible example. |
Sorry for the delay, I've been in a big rush the past weeks I'll try to
send you a code to reproduce by the end of the week
…On Tue, Jun 6, 2017 at 7:58 PM Richard Szalay ***@***.***> wrote:
Hi there, I haven't heard back from you on this issue for a while so I'm
going to close it. Please feel free to create a new issue if you manage to
create a reproducible example.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#33 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKQTjWFiN4q9eAc-2wrKl8Ult2BYtGDQks5sBeeQgaJpZM4Nczsx>
.
|
I'm going to close this issue due to lack of activity. If you're able to create a "MCV" example, I'm more than happy to dive deeper and fix the underlying issue. |
Hello, I have a reproducible example below
Below is the output.
MacOS 10.12.6 |
Oddly I still can't reproduce the problem. I'm on Windows, but it works against both .NET and .NET Core. Am I correct in assuming you're using MockHttp 1.5.0? It sounds like something that would have been a problem before 1.3.1 |
Thanks for pointing out this, I've just checked my .csproj file, there was
in there. Then I used below command to force install 1.5.0, everything works fine.
I don't know why 3.0.0 is installed without version parameter. |
That's very strange. 3.0.0 was published in error in place of 1.3.0 but was unlisted so it shouldn't have been accepted unless explicitly requested. |
Yes, and it would be great if you could add a note for this in README file to prevent others from installing a wrong version without specifying version parameter. |
Done, and I've also logged a bug with the dotnet cli team: https://github.com/dotnet/cli/issues/7492 |
Hi Richard, I confirm I have version 1.5.0, my code is a bit different, since I do an explicit dispose on the HttpResponseMessage after extracting the content: public async Task HttpSendAsync(HttpRequestMessage requestMessage, X509Certificate2 sslCertificate = null)
|
I can now reproduce the issue, and I'll look at patching it. FYI there's no need to dispose the response unless you are keeping a reference to it somewhere.
|
This is fixed in 1.5.1 (just released) |
It would be nice to have an option to make it return a new HttpResponseMessage on every call.
I have a code that disposes the message after extracting the contents and unit tests broke because the response instance gets disposed inside the mock.
System.ObjectDisposedException occurred
Message: Exception thrown: 'System.ObjectDisposedException' in System.Net.Http.dll
Additional information: Cannot access a disposed object.
The text was updated successfully, but these errors were encountered: