I've installed the Clr Heap Allocation Analyzer extension and in a project I see something that I quite don't understand, I've got a method with a signature
public Task<int> ExecuteAsync(string sql, dynamic param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
param = SetModificationValuesForGlobalRing(param);
return _sqlPolicy.ExecuteAsync(async () =>
{
int result;
using (var connection = new SqlConnection(_connectionString))
{
await connection.OpenAsync();
result = await connection.ExecuteAsync(sql, param as object, transaction, commandTimeout, commandType);
}
return result;
});
}
This tools' giving me a warning on the method and all the parameters that says
The compiler will emit a class that will hold this as a field to allow capturing of this closure.
I don't know why this behaviour happens, is it due to the optional parameters?