Strange error after deployment - "Failed allocation for XX blocks"

Hi all,
today I face the strange behaviour of my FEZ Raptor. After uploading the application from VS2012 the debugger was quite a long time “silent” and seems not working and after this there is following in the Output window. It seems that garbage collector is trying something but without success. I have try to reset/unplug/plug again and the behaviour is the same.
Day ago I have uploaded this application a lot of time without this issue and now I have this problem. I am little bit disappointed by this behaviour because it seems there is quite often some new and new and new behaviour…

I am writing an application which should be of course as stable as possible because it will be used commercially for monitoring of some technology(GSM connection through RS232, another two RS232 communication, Ethernet monitoring(not yet implemented)) so I am afraid I am able to do this - but actually I do not have any other solution as HW and everything else is almost ready. So I hope I will be able to make stable application for my customer…

Thank for help.

===================================================================
Output from VS Output window

Found debugger!

Create TS.

Loading start at 202d8818, end 20307cac

Assembly: mscorlib (4.3.1.0) Assembly: Microsoft.SPOT.Native (4.3.1.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.3
.1.0) Assembly: System.Security (4.3.1.0) Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Graphics (4.3.1.0) Assembly: Microsoft.SPOT.TinyCore (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0) Assembly: System.IO (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0) Assembly: Microsoft.SPOT.Touch (4.3.1.0)
Assembly: Microsoft.SPOT.Ink (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Loading Deployment Assemblies.

Attaching deployed file.

Assembly: Gadgeteer (2.43.1.0) Attaching deployed file.

Assembly: GHI.Hardware (4.3.6.0) Attaching deployed file.

Assembly: System (4.3.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.3.6.0) Attaching deployed file.

Assembly: MTC2 (1.0.0.0) Attaching deployed file.

Assembly: GHI.Usb (4.3.6.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.3.1.0) Resolving.

GC: 1msec 344568 bytes used, 66761196 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 66761196 bytes

Type 17 (ASSEMBLY ): 36288 bytes

Type 1E (BINARY_BLOB_HEAD ): 308184 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.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.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.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.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.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.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.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.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.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Touch.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\Microsoft.SPOT.Ink.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.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.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.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.3\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.3 SDK\Libraries\le\GHI.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI NETMF v4.3 SDK\Libraries\le\GHI.Usb.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Mainboards\FEZRaptor\NETMF 4.3\le\GHIElectronics.Gadgeteer.FEZRaptor.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘d:\Projects\Monti\MTC2\MTC2\bin\Debug\le\MTC2.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
GC: 2762msec 67051020 bytes used, 54744 bytes available
Type 0F (STRING ): 1128 bytes
Type 11 (CLASS ): 12648 bytes
Type 12 (VALUETYPE ): 1128 bytes
Type 13 (SZARRAY ): 5808 bytes
Type 03 (U1 ): 1164 bytes
Type 04 (CHAR ): 1032 bytes
Type 07 (I4 ): 1332 bytes
Type 0F (STRING ): 216 bytes
Type 11 (CLASS ): 2064 bytes
Type 15 (FREEBLOCK ): 54744 bytes
Type 16 (CACHEDBLOCK ): 264 bytes
Type 17 (ASSEMBLY ): 36288 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 540 bytes
Type 1D (OBJECT_TO_EVENT ): 240 bytes
Type 1E (BINARY_BLOB_HEAD ): 323508 bytes
Type 1F (THREAD ): 1920 bytes
Type 20 (SUBTHREAD ): 240 bytes
Type 21 (STACK_FRAME ): 66662328 bytes
Type 27 (FINALIZER_HEAD ): 216 bytes
Type 31 (IO_PORT ): 180 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 4248 bytes
GC: 2763msec 67082124 bytes used, 23640 bytes available
Type 0F (STRING ): 1176 bytes
Type 11 (CLASS ): 12648 bytes
Type 12 (VALUETYPE ): 1128 bytes
Type 13 (SZARRAY ): 5844 bytes
Type 03 (U1 ): 1200 bytes
Type 04 (CHAR ): 1032 bytes
Type 07 (I4 ): 1332 bytes
Type 0F (STRING ): 216 bytes
Type 11 (CLASS ): 2064 bytes
Type 15 (FREEBLOCK ): 23640 bytes
Type 17 (ASSEMBLY ): 36288 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 540 bytes
Type 1D (OBJECT_TO_EVENT ): 240 bytes
Type 1E (BINARY_BLOB_HEAD ): 323508 bytes
Type 1F (THREAD ): 1920 bytes
Type 20 (SUBTHREAD ): 240 bytes
Type 21 (STACK_FRAME ): 66693564 bytes
Type 26 (WAIT_FOR_OBJECT_HEAD): 48 bytes
Type 27 (FINALIZER_HEAD ): 216 bytes
Type 31 (IO_PORT ): 180 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 4248 bytes
Failed allocation for 17 blocks, 204 bytes

GC: 2770msec 67082316 bytes used, 23448 bytes available
Type 0F (STRING ): 1176 bytes
Type 11 (CLASS ): 12708 bytes
Type 12 (VALUETYPE ): 1128 bytes
Type 13 (SZARRAY ): 5844 bytes
Type 03 (U1 ): 1200 bytes
Type 04 (CHAR ): 1032 bytes
Type 07 (I4 ): 1332 bytes
Type 0F (STRING ): 216 bytes
Type 11 (CLASS ): 2064 bytes
Type 15 (FREEBLOCK ): 23448 bytes
Type 17 (ASSEMBLY ): 36288 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 540 bytes
Type 1D (OBJECT_TO_EVENT ): 240 bytes
Type 1E (BINARY_BLOB_HEAD ): 323688 bytes
Type 1F (THREAD ): 1920 bytes
Type 20 (SUBTHREAD ): 240 bytes
Type 21 (STACK_FRAME ): 66693564 bytes
Type 27 (FINALIZER_HEAD ): 216 bytes
Type 31 (IO_PORT ): 180 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 4248 bytes
Failed allocation for 39 blocks, 468 bytes

Sorry, it was my mistake!
I was to eager to solve the problem with Debug.Print() while not connected to VS or MFDeploy so I have simply created my new Debug class with Print inside checking Debugger.IsAttached. Then I renamed it to MyDebug by VS feature Find and Rename and of course the inner Debug.Print() was also renamed to MyDebug.Print() so you can imagine the consequences…

Wrong code after Find and Rename (= my mistake)

using System;
using Microsoft.SPOT;

namespace MTC2
{
  public static class MyDebug
  {

    /// <summary>
    /// Print only when there is somebody listenning (VS debugger or MFDeploy Connected)
    /// </summary>
    /// <param name="stringToPrint"></param>
    public static void Print(string stringToPrint)
    {
      if (System.Diagnostics.Debugger.IsAttached)
      {
        MyDebug.Print(stringToPrint);
      }
    }
  }
}

After renaming inner MyDebug.Print to Debug.Print() everything works although I had to reset/disconnect/connect Fez Raptor couple of times to be able to upload new corrected application again:

Looking for a device on transport 'USB’
Starting device deployment…
Iteration 0
Iteration 1



Iteration 58
Iteration 59

but this was probably caused by that defect application previously uploaded…

Thanks for help!