4


I'm using NetMQ for inter-process data communication.
I'm using the NuGet package version 3.3.2.2 on .Net 4.5
I want to create a simple message from a string and send it over a RequestSocket.

I keep getting System.ArgumentNullException although non of the instances are null in any point.

my self containing code:

static void Main(string[] args)
{
    string exampleString = "hello, world";

    byte[] bytes = new byte[exampleString.Length * sizeof(char)];
    if (bytes == null)
    {
        return;
    }

    System.Buffer.BlockCopy(exampleString.ToCharArray(), 0, bytes, 0, bytes.Length);

    var clientMessage = new NetMQ.Msg();
    clientMessage.InitEmpty();

    if (!clientMessage.IsInitialised)
    {
        return;
    }

    clientMessage.Put(bytes, 0, bytes.Length); //throws exception!

}
David Haim
  • 25,446
  • 3
  • 44
  • 78

1 Answers1

2

When you call Put it calls Buffer.BlockCopy(src, 0, Data, i, len);

From github

public void Put([CanBeNull] byte[] src, int i, int len)
{
    if (len == 0 || src == null)
        return;

    Buffer.BlockCopy(src, 0, Data, i, len);
}

In this point Data is null, and Buffer.BlockCopy throws the ArgumentNullException

Try to initalize it by calling InitPool or InitGC.

Guy
  • 46,488
  • 10
  • 44
  • 88