When running on docker image (microsoft/aspnetcore-build:2) I get Unhandled Exception: System.Net.Sockets.SocketException: Cannot assign requested address
It worked before update to 2.0 and it works now on Windows dev machine.
Projects are .NET Core 2.0 & .NET Standard 2.0.
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-preview2-final" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-preview1" />
Stacktrace:
Unhandled Exception: System.Net.Sockets.SocketException: Cannot assign requested address
at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext)
at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory1.FromAsyncImpl[TArg1](Func4 beginMethod, Func2 endFunction, Action1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions)
at Npgsql.NpgsqlConnector.<ConnectAsync>d__141.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlConnector.<RawOpen>d__139.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlConnector.<Open>d__136.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlConnection.<Open>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlConnection.<>c__DisplayClass26_0.<<OpenAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlDatabaseCreator.<ExistsAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.<EnsureDeletedAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at EkoLab.Domain.Commands.SetupDatabaseCommand.SetupDatabaseCommandHandler.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EkoLab.Decorators.ValidateAsyncCommandDecorator1.<HandleAsync>d__3.MoveNext() in /app/server/EkoLab/Decorators/ValidateAsyncCommandDecorator.cs:line 36
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EkoLab.Decorators.LogAsyncCommandDecorator1.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EkoLab.Startup.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()`
Did you ever figure this out? Having the same issue here.
Sorry for not commenting sooner.
Can someone please confirm that this issue occurs with 2.0.0 final (the above report was on preview1)? Also, please note that starting with 2.0.0 the Npgsql.EntityFrameworkCore.PostgreSQL.Design no longer exists, everything is in the main Npgsql.EntityFrameworkCore.PostgreSQL package.
Finally, note that many people are successfully using the Npgsql EF Core provider 2.0.0. In addition, the error message (Cannot assign requested address) indicates a low-level socket/networking issue rather than an Npgqsl-specific issue, I'd advise looking for general help with that error.
@roji on Windows everyhing is ok (.NET core 2.0 and full .NET) only when using docker (image: microsoft/aspnetcore-build:2) an error occurres .
On Ubuntu Server 16.04 LTS with .NET core 2.0 everything is ok.
So yes, I think you are right and there is something wrong with docker or docker image.
Unfortunately I'm not going to have any time to help you debug this issue... try searching for this error message regardless of Npgsql, hopefully the answer will pop up somewhere...
Am closing this although please feel free to post back with more details or conclusions/resolutions.
@cime @sethen Are you guys running both your asp.net application as well as your postgres instance in docker containers using docker compose?
@WonderPanda yes I do.
@WonderPanda No... I actually can't remember now how I resolved this issue. I just know it's no longer an issue for me.
@cime I was having the same issue as you originally. I was trying to use a connection string that had localhost in it but running in docker compose. When compose boots up all the containers, localhost isn't valid because they're in a docker network. I just had to change the hostname of the connection string to whatever the name of your postgres service is in your docker compose file.
This is a feature of docker compose which automatically configures a network between the containers and routes the hostname for you.
For me the same issue was fixed by using the Gateway address of the database Docker container.
Note: I do not have the db listed in my docker-compose.yml. Instead I start it separately in the background using a different docker-compose file.
Solution for me was simply using host.docker.internal instead of localhost in your connection string (this is only supported on Docker for Windows and Mac, but not on Linux).
Solution for me was simply using
host.docker.internalinstead oflocalhostin your connection string (this is only supported on Docker for Windows and Mac, but not on Linux).
hey buddy you save my life
Solution for me was simply using
host.docker.internalinstead oflocalhostin your connection string (this is only supported on Docker for Windows and Mac, but not on Linux).
so thanks bro
Most helpful comment
@cime I was having the same issue as you originally. I was trying to use a connection string that had localhost in it but running in docker compose. When compose boots up all the containers, localhost isn't valid because they're in a docker network. I just had to change the hostname of the connection string to whatever the name of your postgres service is in your docker compose file.
This is a feature of docker compose which automatically configures a network between the containers and routes the hostname for you.