OK this has been killing me for the last 3 days but I have narrowed it down to the addition of a reference to System.Security that stops my application running on the Netduino 3 Wi-Fi.
Writing a project to log depth readings from a septic system to an Azure Web App. When I first got my boards I wrote the Blinky app and deployed to test the boards, all successful. So went on to use MFDeploy to configure the network settings then deployed and ran the Blinky program. Confirmed that the ACK light went from yellow to green and my router could see the device.
Every time I deployed my app and tried to debug the board hangs up and does not respond. I have to put it into DFU Mode and use the firmware updater to erase the program. Once the program is erased the board works as expected.
After much messing around I can reproduce the problem by just going to the Blinky application and adding a reference to System.Security. No code changed just going to references and adding System.Security (4.3.1.0).
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.Threading;
namespace Blinky
{
public class Program
{
public static void Main()
{
Debug.Print("Starting...");
// create an output port (a port that can be written to) and wire it to the onboard LED
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
// run forever
while (true)
{
Debug.Print("On");
led.Write(true); // turn on the LED
Thread.Sleep(250); // sleep for 250ms
Debug.Print("Off");
led.Write(false); // turn off the LED
Thread.Sleep(250); // sleep for 250ms
}
}
}
}
Without a reference to System.Security this program deploys fine, runs and outputs to debug:
The ACK light initially is yellow and after few seconds goes green. The onboard LED blinks…
Create TS.
Loading start at 8065cac, end 808cd2c
Assembly: mscorlib (4.3.1.0)
Assembly: Microsoft.SPOT.Native (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Net (4.3.1.0)
Assembly: Microsoft.SPOT.Net.Security (4.3.1.0)
Assembly: System (4.3.1.0)
Assembly: System.Net.Security (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0)
Assembly: System.IO (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Netduino.IP (1.0.0.0)
Assembly: Netduino.IP.Interop (1.0.0.0)
Assembly: Netduino.IP.LinkLayers.CC3100 (1.0.0.0)
Assembly: SecretLabs.NETMF.Diagnostics (4.3.1.0)
Assembly: GoBus (1.5.0.0)
Assembly: SecretLabs.NETMF.Hardware.Netduino (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.OneWire (4.3.1.0)
Loading Deployment Assemblies.
Attaching deployed file.
Assembly: Blinky (1.0.0.0)
Resolving.
The debugging target runtime is loading the application assemblies and starting execution.
Ready.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Net.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP.Interop'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP.LinkLayers.CC3100'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\SecretLabs.NETMF.Diagnostics.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\GoBus.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\SecretLabs.NETMF.Hardware.Netduino.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.OneWire.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'D:\OneDrive\NetDuino\Programs\Blinky\Blinky\bin\Debug\le\Blinky.exe', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Starting...
On
Off
On
Simply adding a reference to System.Security and start debugging. The following is displayed:
Create TS.
Loading start at 8065cac, end 808cd2c
Assembly: mscorlib (4.3.1.0)
Assembly: Microsoft.SPOT.Native (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Net (4.3.1.0)
Assembly: Microsoft.SPOT.Net.Security (4.3.1.0)
Assembly: System (4.3.1.0)
Assembly: System.Net.Security (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0)
Assembly: System.IO (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Netduino.IP (1.0.0.0)
Assembly: Netduino.IP.Interop (1.0.0.0)
Assembly: Netduino.IP.LinkLayers.CC3100 (1.0.0.0)
Assembly: SecretLabs.NETMF.Diagnostics (4.3.1.0)
Assembly: GoBus (1.5.0.0)
Assembly: SecretLabs.NETMF.Hardware.Netduino (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.OneWire (4.3.1.0)
Loading Deployment Assemblies.
Attaching deployed file.
Assembly: System.Security (4.3.1.0)
Attaching deployed file.
Assembly: Microsoft.SPOT.Security.PKCS11 (4.3.1.0)
Attaching deployed file.
Assembly: Blinky (1.0.0.0)
Resolving.
The debugging target runtime is loading the application assemblies and starting execution.
Ready.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Net.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP.Interop'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'Netduino.IP.LinkLayers.CC3100'
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\SecretLabs.NETMF.Diagnostics.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\GoBus.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.3\le\SecretLabs.NETMF.Hardware.Netduino.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Hardware.OneWire.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.12.dll' (Managed): Loaded 'D:\OneDrive\NetDuino\Programs\Blinky\Blinky\bin\Debug\le\Blinky.exe', Symbols loaded.
No debug messages are shown, the ACK light never lights up, the onboard LED never lights. Only way to recover the board is to erase the program with firmware updater.
Any pointer would be most gratefully received, I need to reference the System.Security as I want to do a HMACSHA256 encoding and need to be able to use the KeyHashAlgorithm class.
/// <summary>
/// Computes a HMAC SHA 256 hash for the supplied information
/// </summary>
/// <param name="data">Byte array of the data to produce hash for</param>
/// <param name="key">Private key to use for the hash</param>
/// <returns></returns>
public static byte[] HmacSha256ComputeHash(byte[] data, byte[] secret)
{
using (KeyedHashAlgorithm hmac = new KeyedHashAlgorithm(KeyedHashAlgorithmType.HMACSHA256))
{
hmac.Key = CryptoKey.ImportKey(hmac.Session, secret, CryptoKey.KeyClass.Private, CryptoKey.KeyType.GENERIC_SECRET, false);
return hmac.ComputeHash(data);
}
}
Thanks
Joe