Endpoint.GetAccountNameForNetwork

Jun 30, 2009 at 4:05 PM

I've an application using DisconnectedAgent on Symbol MC70 devices. There are instances out in the field where the networkName parameter can come in as String.Empty, which results in an ArgumentException. The network name comes from the device via ConnectionMonitor, so it's really out of my hands but I suspect it to be some quirkiness from the CellConnection implementation. It seems like there could be a race condition where you can fall into a branch of code thinking you're connected, and then you get disconnected and now the network name starts coming back empty.  My workaround was to create a wrapper class that feeds a null value into the method rather than allowing an empty string to pass through.  I wonder to what detriment it would be to change the method implementation to fall back to Default if networkName is null or empty.  Consider the implementation of ContainsConfigForNetwork. If there is a Default, the return value is true regardless of whether the networkName is null or empty.

Wrapper Class Method:

<font size="2">

 

</font>

public string GetAccountNameForEndpoint(string endpointName, string networkName) {<font size="2">

 

</font>

// if networkName is empty an exception is thrown, so pass a null instead.

<font size="2">

 

</font>

// this is the reason for this class' existence, to prevent this error

<font size="2">

 

</font>

return wrappedCatalog.GetAccountNameForEndpoint(endpointName, String.IsNullOrEmpty(networkName) ? null : networkName);

}

PS: Endpoint.GetAddressForNetwork has a similar implementation. Null is a special value that allows triggers the Default, whereas String.Empty results in an exception.

Coordinator
Aug 4, 2009 at 4:27 PM

Hi Eric,

Your suggestion makes perfect sense. In fact, a null network name is getting back the default address and account name right now, so, it definitely makes sense to behave in the same way with an Empty string.

I'm adding the issue and implementing on the code with its corresponding unit tests.

Thanks