AssignNetworkingStackTo(wifi_RS21.Interface) Error

A application that has been working without errors is now showing the following exception.

Using GHI .NET Micro Framework 4.2

Partial code that I have added a Try, Catch to code that was working OK…



        private void StartServer()
        {
            display_T35.SimpleGraphics.Clear();
            display_T35.SimpleGraphics.DisplayText("Trying to connect to WiFi. Wait..", NBFont, Colors.Red, 3, 5);

            if (!wifi_RS21.Interface.IsOpen)
            {
                wifi_RS21.Interface.Open();
                try
                {
                    NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);
                }
                catch (GHI.Premium.Net.NetworkInterfaceExtensionException bummer)
                {
                    Debug.Print(bummer.errorCode.ToString());
                    //errorCode	0x00000002  GHI.Premium.Net.NetworkInterfaceExtensionException.ErrorCode {int}
                }
            }


/*
RS9110 driver version Number is 4.4.5
#### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (1) ####
#### Message:
#### GHI.Premium.Net.NetworkInterfaceExtension::Activate [IP: 001a] ####
#### ServerSpider.Program::StartServer [IP: 004c] ####
#### ServerSpider.Program::Startbutton_ButtonPressed [IP: 001e] ####
#### Gadgeteer.Modules.GHIElectronics.Button::OnButtonEvent [IP: 0058] ####
#### Gadgeteer.Modules.GHIElectronics.Button::_input_Interrupt [IP: 0068] ####
#### Gadgeteer.Interfaces.InterruptInput::OnInterruptEvent [IP: 0055] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll
Error invoking method “Gadgeteer.Interfaces.InterruptInput” (check arguments to Program.BeginInvoke are correct)
*/

Any idea what the ‘errorCode 0x00000002’ is and what causes the exception?

Here are the error codes:

public enum ErrorCode
        {
            UnknownNetworkInterface,
            ReservedInterface,
            AlreadyActivated,
            OtherInterfaceIsActivated,
            AlreadyDeactivated,
            AlreadyJoined,
            WrongSSID,
            AuthenticationFailed,
            InvalidChannel,
            UnKnownError,
            HardwareNotEnabled,
            HardwareCommunicationFailure,
            HardwareCommunicationTimeout,
            HardwareFirmwareVersionMismatch,
            HardwareFirmwareCorrupted,
            NotSupported,
            RequestTimeout,
            NotOpen
        }

So numbering of enum starts a 0, so 2 = AlreadyActivated.

Sometimes an InterfaceExtension is still activated, even if device is rebooted.
You can check this by IsActivated property.
If this is the case just do as follows:

if (wifi_RS21.IsActivated)
{
   wifi_RS21.Close();
   wifi_RS21.Dispose();
   wifi_RS21 = new .... // recreate interface extension here
}

Thanks for both replies…

Both are helpful!

UPDATE: This solved the exception



            if (wifi_RS21.Interface.IsActivated)
            {
                if (wifi_RS21.Interface.IsOpen)
                {
                    //Exception here if used and not tested for Open() first
                    wifi_RS21.Interface.Close(); 
                }
            }

            if (!wifi_RS21.Interface.IsOpen)
            {
                wifi_RS21.Interface.Open();
                try
                {
                    if (wifi_RS21.Interface.NetworkInterface.NetworkInterfaceType != Microsoft.SPOT.Net.NetworkInformation.NetworkInterfaceType.Wireless80211)
                        NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);
                }
                catch (GHI.Premium.Net.NetworkInterfaceExtensionException bummer)  //No exception was received!
                {
                    Debug.Print(bummer.errorCode.ToString());
                }
            }