ASSERT using String.Concat( )

One of my usual goofy questions. But I don’t mind asking because I do not understand why Concat( ) gives the ASSERT

Using a Fez.Spider
Using >NET Micro Framework 4.1

The main reason I am asking is because I had to spend over an hour trying to recover my Spider. Upon power up or a button reset my simple code would run and immediately go into ASSERT. I finally got the right moment to do an Erase (Using MFDeploy) and saved my Spider from Brick heaven or would that be Brick hell?

Is there a way I can do/use the ’ string result = String.Concat(parts); ’ without causing the ASSERT?

In case you are wondering: All I was trying to do is make two strings of all the characters in the tiny fonts (with the control characters) and display as a string.
It is only an experiment as I wanted to display all characters received (On the T-35 display) from a bluetooth device for troubleshooting.

Partial code attached that gives the error



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    { 
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            beginhere();
        }

        void beginhere()
        {
            //Do not allow code to run until button is pressed
            //This is because of *****ASSERT***** when using string result = String.Concat(parts);
            //It was almost impossible to recover my Spider. The code would run upon a reset and
            //MFDeploy gave exception when trying to Erase. I spent over an hour trying to catch
            //the correct moment so MFDeploy could erase the app. I added the button so code will
            //not run after the exception and I can erase the app. for testing
			
            while(!button.IsPressed)
            {
                Debug.Print("CANNOT RUN - SAFETY CHECK");
                if (button.IsPressed)
                {
                    break; //Allow code to run
                }
            }

            Debug.Print("RUNNING CODE - SAFETY CHECK");

            Bitmap TBitmap;
            TBitmap = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);

            Font myFont = Resources.GetFont(Resources.FontResources.NinaB);
          
            Text text = new Text();
            Text textS = new Text();
			
            // Set Fonts
            text.Font = Resources.GetFont(Resources.FontResources.NinaB);
            textS.Font = Resources.GetFont(Resources.FontResources.small);

            char[] NinaBfont = new char[130];
            string[] parts = new string[130];

            uint x = 2;
            uint y = 0;
            uint W = 0;
            uint H = 0;
			
            y += (uint)text.Font.Height + 3;
            x = 2;

            for (ushort i = 0; i <= 128; ++i)
            {
                char T = Convert.ToChar(i); 
                W = (uint) text.Font.CharWidth(T);
                H = (uint)text.Font.Height;
                NinaBfont[i] = T;

                string part = String.Empty;
                part = T.ToString();
                parts[i] = part;

                x += (W + 2);
                
                if(x > 300)
                {
                    x = 2;
                    y+= (H + 2);
                }
            }

            // *****ASSERT***** here using Concat
            string result = String.Concat(parts);
        }
    }
}


Have a GREAT day!

Well my first pointer would be you’re using the Gadgeteer code methodology but you’re not really letting the core Gadgeteer commence as your beginhere() doesn’t finish and let the Gadgeteer stack start clean. Does the same code, but in a non-Gadgeteer app, behave the same?

Brett

Thanks for the reply.

  1. I will restructure the code and try it again.

  2. For the moment all I have is the Fez.Spider to test it on

  3. Big three… I have to admit out loud that I do not fully understand…
    “but you’re not really letting the core Gadgeteer commence as your beginhere() doesn’t finish and let the Gadgeteer stack start clean”

I guess I have to say that I did not know it mattered.

All the code worked as I expected (The original code was much longer) using the beginhere() method.
It worked well until I added the string concat. The source strings looked properly formed but then again the strings contain the control character within the fonts.

I will take the source strings and try a Concat(parts) in a non gadgeteer .Net app and see if I have issues because of the string content.

Thanks for your reply.



string result = String.Empty; 
result = String.Concat(parts);


http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx

Your app never finishes, the same as this…

Also, Spider is fine, just create an EMX based non-Gadgeteer project.