MikrotikDotNet icon indicating copy to clipboard operation
MikrotikDotNet copied to clipboard

cmd.ExecuteReaderDynamic() failed when mikrotik returns multiple "keys" in row

Open uom42 opened this issue 2 years ago • 4 comments

...

conn.Open();
var cmd = conn.CreateCommand("ip firewall address-list print");

Result (Raw api response):

!re=.id=*CC997=list=list1=address=192.168.1.1=creation-time=feb/13/2023 02:26:04=dynamic=false=dynamic=false=disabled=false=comment=aaa
!re=.id=*CC998=list=list1=address=192.168.1.0/24=creation-time=feb/13/2023 02:26:04=dynamic=false=dynamic=false=disabled=false=comment=bbb

And when we trying to ExecuteReaderDynamic():

var result = cmd.ExecuteReaderDynamic();
foreach (dynamic ip in result)
	Debug.WriteLine($"{ip.Id} - {ip.Address} - {ip.disabled}"); 

we found that each row have two keys "dynamic" and have exception!

May be we need ExecuteReaderDynamic() bool flag to ignore dublicate keys or some else?

uom42 avatar Feb 17 '23 19:02 uom42

Hi @uom42 , Could you please send the exception details?

janmohammadi avatar Feb 17 '23 19:02 janmohammadi

System.ArgumentException: 'An item with the same key has already been added. Key: dynamic'

uom42 avatar Feb 17 '23 20:02 uom42

Hi @uom42 , Could you please send the exception details?

Mikrotik raw responce have TWO "dynamic" keys in each row!

uom42 avatar Feb 17 '23 20:02 uom42

Sorry, but we can't ignore duplicates. In this particular example, the meaningful key is the second! We need some way to index duplicate keys and understand that they are duplicates ...

uom42 avatar Feb 17 '23 20:02 uom42