When calling /snmp/print with a ExecuteScalarOrDefault method and the /snmp location value is empty string, the API throws an exception.
System.InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at tik4net.Api.ApiCommand.ExecuteScalarInternal(String target, Boolean allowReturnDefault, String defaultValue)
at tik4net.Api.ApiCommand.ExecuteScalarOrDefault()
at ...
It probably means that the code isn't checking for empty string output correctly and or should be using SingleOrDefault instead of Single when allowReturnDefault is true.
When calling
/snmp/print
with aExecuteScalarOrDefault
method and the/snmp location
value is empty string, the API throws an exception.According to the stacktrace, it looks like it is happening in one of the
.Single
calls in: https://github.com/danikf/tik4net/blob/e286e11b69b967d7ef8979e6b799302563846610/tik4net/Api/ApiCommand.cs#L305It probably means that the code isn't checking for empty string output correctly and or should be using
SingleOrDefault
instead ofSingle
whenallowReturnDefault
is true.RouterOS version: 7.9.2 MikroTik config:
Example code: