ArgumentNullException: Value cannot be null. (Parameter 'buffer.Array')
Closed this issue · 2 comments
What is the current behavior?
ArgumentNullException: Value cannot be null. (Parameter 'buffer.Array')
at System.Net.WebSockets.WebSocketValidate.ValidateArraySegment(ArraySegment`1 arraySegment, String parameterName)
at System.Net.WebSockets.ManagedWebSocket.SendAsync(ArraySegment`1 buffer, WebSocketMessageType messageType, Boolean endOfMessage, CancellationToken cancellationToken)
at Deepgram.Clients.LiveTranscriptionClient.Send(ArraySegment`1 data, CancellationToken token)
at Deepgram.Clients.LiveTranscriptionClient.ProcessSenderQueue()
Steps to reproduce
Honestly, I'm not sure but I thought you'd like to know. From what I see there is no possibility of a null bytes array in SendData
in my code (it has nullable and it's fairly straightforward) but I couldn't find an explanation from looking at your code either. So, I don't expect your to necessarily fix this but maybe you'll see something that I didn't.
Here's the code I use for sending bytes:
var buffer = args.Buffer;
if (buffer.Length != args.BytesRecorded)
{
var newBuffer = new byte[args.BytesRecorded];
Array.Copy(buffer, newBuffer, args.BytesRecorded);
buffer = newBuffer;
}
_deepgramLive.SendData(buffer);
So, impossible for buffer to be null. And in the other place you call EnqueueForSending (keep alive)
Expected behavior
No crash :D
Please tell us about your environment
- Operating System/Version: Windows 11
- Language: C#
Other information
It's a small optimization, but I saw you call this:
deepgram-dotnet-sdk/Deepgram/Clients/LiveTranscriptionClient.cs
Lines 176 to 177 in 460a300
in KeepAlive. But since those bytes will never change, it would be better to only serialize one in a static bytes array field and reuse the same bytes array instead.
Will check to see if this still applies for v4
.
This should no longer be an issue in v4
.