我正在使用NetMQ进行进程间数据通信.
我在NuGet 4.5上使用的是3.3.2.2版的.Net软件包
我想从一个字符串创建一个简单的消息,并通过一个RequestSocket发送它。
我一直得到System.ArgumentNullException,尽管非实例在任何一点上都是空的。
我自己包含的代码:
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!
}发布于 2016-03-23 09:56:08
当您调用Put时,它调用Buffer.BlockCopy(src, 0, Data, i, len);
来自github
public void Put([CanBeNull] byte[] src, int i, int len)
{
if (len == 0 || src == null)
return;
Buffer.BlockCopy(src, 0, Data, i, len);
}在这一点上,Data是null,Buffer.BlockCopy抛出ArgumentNullException
尝试通过调用InitPool或InitGC来使其无效。
https://stackoverflow.com/questions/36174377
复制相似问题