ILC mode will clear out ParamName for ArgumentNullException
System.Net.Sockets NullArgs_Throw() test runs fine in netcore/netfx/uap mode. But in ILC ('uap-aot') mode it is failing. It seems that the ParamName field has been optimized away:
public void NullArgs_Throw(SocketImplementationType type)
{
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
sock.SendPacketsAsync(null);
});
Assert.Equal("e", ex.ParamName); //failure here, ex.ParamName == null
}
}
}
Here is the implementation for SendPacketsAsync:
public bool SendPacketsAsync(SocketAsyncEventArgs e)
{
...
if (e == null)
{
throw new ArgumentNullException(nameof(e));
}
...
}
https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception.-ctor?view=netcore-1.1#System_ArgumentNullException__ctor_System_String_ No matter what paramName value I passed in, ex.ParamName is always null.
But if I do:
SocketAsyncEventArgs e = null;
ArgumentNullException testEx = new ArgumentNullException(nameof(e));
This works, testEx.ParamName is "e".
cc: @davidsh
Because of this problem, the NullList_Throws() fails as well:
public void NullList_Throws(SocketImplementationType type)
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
SendPackets(type, (SendPacketsElement[])null, SocketError.Success, 0);
});
Assert.Equal("e.SendPacketsElements", ex.ParamName); // failure, ex.ParamName == null
}
This is by design.
The recommended remedy is to use AssertExtensions.Throws<>() to test ParamNames. It will test the paramname on non-uapaot platforms and ignore it on uapaot.
@AtsushiKan Thank you! I will fix those test cases.