zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 745 forks source link

Simplest example doesn't work #1099

Open LexaGV opened 3 months ago

LexaGV commented 3 months ago

Environment

NetMQ Version: latest at 6 Aug (probably 4.0.0.0 as *.csproj says). Built from sources for .NET FW 4.8 Operating System: Win7 x64 SP1 .NET Version: Framework 4.8

Sample is:

var server = new ResponseSocket("@tcp://localhost:5556");

Fails with error:

Unexpected null of type AsyncSocket
at NetMQ.Assumes.NotNull[T](T o) in C:\PRG\NetMQ_project\NetMQ\Utils\Assumes.cs:line 12
at NetMQ.Core.Transports.Tcp.TcpListener.SetAddress(String addr) in C:\PRG\NetMQ_project\NetMQ\Core\Transports\Tcp\TcpListener.cs:line 126
at NetMQ.Core.SocketBase.Bind(String addr) in C:\PRG\NetMQ_project\NetMQ\Core\SocketBase.cs:line 569
at NetMQ.NetMQSocket.Bind(String address) in C:\PRG\NetMQ_project\NetMQ\NetMQSocket.cs:line 188
at NetMQ.NetMQSocket..ctor(ZmqSocketType socketType, String connectionString, DefaultAction defaultAction) in C:\PRG\NetMQ_project\NetMQ\NetMQSocket.cs:line 65
at NetMQ.Sockets.ResponseSocket..ctor(String connectionString) in C:\PRG\NetMQ_project\NetMQ\Sockets\ResponseSocket.cs:line 17
...

If you look at SetAddress(TcpListener.cs line 121), it's smth strange: the only place where m_handle is initialized is line 130:

m_handle = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

...but immediately before this line you check:

Assumes.NotNull(m_handle);

What?? How you can check it's not null if you never initialized it? Seems somebody too anxious for "null" value that forgot business logic - main thing he should worry about.

After elementary fix (remove illogical Assert) server at least started.