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

Npgsql.NpgsqlException (0x80004005): Exception while writing to stream: Cannot access a disposed object. #2051

Closed
asmaa-ayman opened this issue Jul 8, 2018 · 2 comments

Comments

@asmaa-ayman
Copy link

Hello,

I am getting this error each time I run more than two nunit tests in a test suit. It doesn't show up when each test is run separately.

Npgsql.NpgsqlException (0x80004005): Exception while writing to stream ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at Npgsql.NpgsqlWriteBuffer.d__26.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlWriteBuffer.cs:line 125
at Npgsql.NpgsqlWriteBuffer.d__26.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlWriteBuffer.cs:line 134
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Npgsql.NpgsqlCommand.d__84.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 875
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.d__100.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1233
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1132
at Npgsql.NpgsqlCommand.ExecuteReader() in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1102

I am using Npgsql version: 4.0.0 and .NET Framework 4.5.2

@roji
Copy link
Member

roji commented Jul 8, 2018

You're going to have to post some code to show what you're doing. But the problem is probably that you're sharing connections between tests that are running concurrently, which isn't allowed. Make sure each connection is used only within each test's method (don't declare the connection on the class).

@asmaa-ayman
Copy link
Author

You are right. I was declaring the connection on class level. Thank you so much.

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

No branches or pull requests

2 participants