NetworkInterface command causes exception

Hello all,

In a RPi console app under Xojo 2022 R3.2 running in Buster in an RPi4 8Gig device the following code results in an exception.

Dim n As NetworkInterface = System.NetworkInterface(0)

I have also tried Dim n As NetworkInterface = System.NetworkInterface(1) too and have limited the connection to Ethernet only, from both Ethernet and WiFi. Also tried in Xojo 2019R1.1

Dim n as NetworkInterface //= System.GetNetworkInterface(0)

Same result. What am I doing wrong???

Perhaps I am not waiting long enough to run this - it is started by a systemd service. On boot it fails at the spot written above, but if I run the systemd command after boot then it starts fine without errors…


Make sure your service has the network set as a prerequisite. That should fix this.


you could look if your network is listed before you access any index?

For i As Integer = 0 To System.NetworkInterfaceCount - 1

at pi3 menu settings / raspberry pi settings there was a checkbox
network at boot: wait for network

Hi Guys,

@Greg, I tried adding that - no go. I already had some wait statements but this addition did not help…
Here’s what I have for the systemd script:

Description=Axcys Client Service
#After=NetworkManager-wait-online.service dbus.service
#systemctl enable axcys-client-service.system
After=postsgresql.service debus.service





Any other ideas?

Make sure you also add the

Because After doesn’t “imply a relationship” apparently.

Reading the Unit File docs, I get the impression that After merely means that your service is started after the network-online service starts, but that it may be that it hasn’t actually reached a working state yet. Having code to periodically check to see if the network is available and try again in a few seconds may be the right thing to do anyway. I know we tackled this for Xojo Cloud, but I can’t remember what the solution was unfortunately, but it may have been the support of the watchdog protocol that ultimately fixed it.

Hi Greg,

That’s what I did - I wrote code to manage this so that it can start anytime I periodically check for a connection, but it is running. This definitely solved the problem. It was something that was not really apparent when I originally wrote this little app a few years ago, using my Windows machine - there was not waiting, as it was always there!

Thank you again for your help!