Skip to content

NullReferenceException from SocketAsyncEventArgs.InnerStartOperationReceiveMessageFrom #22675

@lextm

Description

@lextm

I was working on a UDP library when I hit this miserable exception. Attached is the minimal project I can think of to reproduce the exception.

SocketAsyncClose.zip

Compile and run this project with no debugger attached, and you should see the exception details,

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.Sockets.SocketAsyncEventArgs.InnerStartOperationReceiveMessageFrom()
   at System.Net.Sockets.Socket.ReceiveMessageFromAsync(SocketAsyncEventArgs e)
   at SocketAsyncClose.Program.<>c__DisplayClass1_0.<Main>b__0() in c:\users\lextm\documents\visual studio 2017\Projects\SocketAsyncClose\SocketAsyncClose\Program.cs:line 36

This piece of code tries to reuse SocketAsyncEventArgs objects. And it works fine if Socket.ReceiveAsync or Socket.ReceiveFromAsync is used.

I tested it on Windows 10 (latest patches, .NET Core 1.0 and 1.1), and both cases give the same exception. I tested on macOS (latest stable. .NET Core 1.0 and 1.1), and cannot reproduce the exception.

Not surprised, as it should be something wrong in SocketAsyncEventArgs.Windows.cs I think and is Windows only.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions