Snippet - Full NETMF Shelling

Full NETMF Shelling

This snippet allows you to launch a full NETMF application inside a new AppDomain and run Main()

3 Likes

This looks great. Does this also works with a gadgeteer app? I mean can I run a gadgeteer app in a new app domain with this code?

Yes, Gadgeteer code still starts at Main(), even though MS automatically populates that for you. Which means this will locate the correct place to start and initialize it. You could just as easily define any other start-point you want, but this is definitely the way to go for any regular application produced from VS.

@ Skewworks: which files should I use to get it working: the ones in my LE or BE folder or the those in my release folder?

I started out with the BE files, altough i’ve tried the le files.

All depended assemblies are been loaded but this line:

asm = Assembly.Load(File.ReadAllBytes(filename))

give me an asm object which is NULL and returns false.

What I’m I doing wrong?

Loading BE files is your problem. :slight_smile: All the GHI devices (and all NETMF devices I’ve used to date) are LE. The null exception is actually a good thing. It’s handling the fact that it’s incompatible and moving on without blowing up.

The file you want is the .PE file in the LE folder that matches your application name. You’ll also want any dependency projects. Do NOT add GHI/MS PE files as these are already on the device and it tends to get a little cranky when it tries to load them a 2nd time. :slight_smile:

What do LE and BE refer to? I’ve seen the LE refer to DOS executables.

It doesn’t seem to work with Glide. It loads the needed assemblies but it hangs when executing the main program. I’ve put a breakpoint to determine if main would be called but it never does. So it exits with false and the app stops running.

I can imagine that my gadgeteer app is the problem, so I’ll test it with a small gadgeteer program and post my results here.

Little Endian & Big Endian.

[quote=“Patrick”]It doesn’t seem to work with Glide. It loads the needed assemblies but it hangs when executing the main program. I’ve put a breakpoint to determine if main would be called but it never does. So it exits with false and the app stops running.

I can imagine that my gadgeteer app is the problem, so I’ll test it with a small gadgeteer program and post my results here.[/quote]

Did you include the Glide dependencies and point to the right PE file? If you’ve got it pointing to the wrong PE it’ll never find main (unless of course you have a main in that PE too). :slight_smile:

@ Dr9 - LE == Little Endian; BE == Big Endian. Has to do with byte order. Endianness - Wikipedia

Yes, I’ve included the LE version of ghielectronics.netmf.glide.pe and pointed to my program terminal.pe.

I just tried it with a glide example from the site:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace Terminal
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.
        static Window window;
        void ProgramStarted()
        {
           
                // Create the Window XML string.           
                string xml;
                xml = "<Glide Version=\"" + Glide.Version + "\">";
                xml += "<Window Name=\"window\" Width=\"320\" Height=\"240\" BackColor=\"FFFFFF\">";
                xml += "<TextBlock Name=\"title\" X=\"0\" Y=\"104\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Simple Example\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"6\" FontColor=\"000000\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
                xml += "</Window>";
                xml += "</Glide>";
                // Resize any loaded Window to the LCD's size.            
                Glide.FitToScreen = true;
                // Load the Window XML string.            
                window = GlideLoader.LoadWindow(xml);
                // Assign the Window to MainWindow; rendering it to the LCD.            
                Glide.MainWindow = window;

            
            Debug.Print("Program Started");
        }
    }
}

the results are the same. It hangs when the glide assembly loads. Stange enough it continues when you randomly adds and remove breakpoints in the code snippet. At the end it exits with false and never finds a main method.

Debugger causes load time to be substantially longer. Not sure why its bit finding Main. You could do a break inside the loop and take a look at each set of methods for each class. I wonder if Glide needs another dependency or if its a Gadgeteer issue.

I did another test, still gadgeteer, but this time without glide and the results are same. It could be a gadgeteer issue.

Definitely Gadgeteer then. I can try having a look at it tonight; not sure how much time I’ll have since I’m preparing for the big distributed computing test next weekend.

ok, I really appreciate your input :slight_smile:

I did one last test with a native netmf app

using System;
using Microsoft.SPOT;

namespace Terminal
{
    public class Program
    {
        public static void Main()
        {
            Debug.Print(
                Resources.GetString(Resources.StringResources.String1));
        }

    }
}

And this works, it shows “Hello World!” in the debug window. So it’s a gadgeteer issue for sure.

Hi Skewworks, did you had some spare time to have a look at this? I’m really stock :frowning:

Shoot. I’m sorry Patrick, with all the holiday stuff (Thanksgiving in the US) and prepping for my oldest’s birthday, Christmas, etc, this completely slipped my mind.

I will make it a priority for tonight, I’ve even booked time in my calendar. :slight_smile:

I know there are more important things in live!! :slight_smile: Family is the most important thing and the best reason, so no hard feelings at all :slight_smile:

Really appreciate your time and knowledge. Congrats with the birthday of your oldest.

Can’t believe I didn’t realize this before. Problem with running Gadgeteer apps in new domains is they reserve pins, it’s bound to fail on launch.