Cobra "Chumby project"

Connect MFDeploy and reset the device to see power up messages to see if these assemblies were in fact loaded on FEZ Cobra (EMX)

See this image: http://files.chrisseto.com/Iwm

Make window project to make sure it works and then use the same project to load a window application from SD

That’s exactly what I have done. It does work as a normal program, just not from the SD card.

Oh, also, as promised, here’s the SRC:
Loader: http://files.chrisseto.com/bnv
Assembly: http://files.chrisseto.com/bOf

I had the same problem: CLR_E_TYPE_UNAVAILABLE.

It’s possible that you have spaces in the name of your dll… remove these by renaming the assembly!

Roel

The assemblies do have underscores in them, but that should be allowed, right?

I think so!

Any other ideas? Anyone wanna download my code and play around with it?

Note: to build the “module”, you need to build it, shift + F6 will do that. The resulting .pe file will be in the debug directory.

Use the same project to run the assembly in 2 ways…here is what I am thinking

  1. make a window application and make sure it runs
  2. from within the same application that is working, add the assembly as a resource and then try to load it dynamically.

Hi Gus,

I’ll try that a little later today and report back, thanks!

Hey Chris

Is the code on VS 2010 ? I kept double clicking the .sln and nothing would happen, finally I used the VS File->Open and see the version error :slight_smile:

I will need to wait till evening to try and get a VS2010 install.

I’ve been tinkering with this for a bit today too, and embedding the assembly as a resource still throws the same exception.

One thing I tried was manually copying the Microsoft.SPOT.TinyCore.pe and Microsoft.SPOT.Graphics.pe dependencies out to the SD card and manually doing an Assembly.Load() on them first, just to see what would happen. I get this:

Assembly: Microsoft.SPOT.TinyCore (4.1.2459.0) needs assembly ‘mscorlib’ (4.1.2459.0)
Assembly: Microsoft.SPOT.TinyCore (4.1.2459.0) needs assembly ‘Microsoft.SPOT.Native’ (4.1.2459.0)
Assembly: Microsoft.SPOT.TinyCore (4.1.2459.0) needs assembly ‘Microsoft.SPOT.Hardware’ (4.1.2459.0)
Assembly: Microsoft.SPOT.TinyCore (4.1.2459.0) needs assembly ‘Microsoft.SPOT.Graphics’ (4.1.2459.0)
#### Exception System.Exception - CLR_E_TYPE_UNAVAILABLE (1) ####
#### System.Reflection.Assembly::Load [IP: 0000] ####
#### LoaderApp.Program::CreateWindow [IP: 0049] ####
#### LoaderApp.Program::Main [IP: 0009] ####
A first chance exception of type ‘System.Exception’ occurred in mscorlib.dll
An unhandled exception of type ‘System.Exception’ occurred in mscorlib.dll

So then I tried copying and Assembly.Load()'ing mscorlib.pe off the SD first, but I get an error indicating the file can’t be found. This whole thing doesn’t really make much sense to me, as mscorlib must already be loaded in order for anything to work at all. It’s almost like the Assembly.Load() call isn’t putting the loaded assembly into the running application’s AppDomain context.

I’m pretty sure this used to work (simply doing an Assembly.Load() on a .pe file on an SD card), so I think there must be something very basic that we’re missing here.

Chris / Chuckie

Can one of you try this by adding a direct reference to the assemblies (core, spot etc.) ?

Rajesh,

The references have already been explicitly added. In particular, Microsoft.SPOT.TinyCore is directly referenced in both projects (the loader and the, um, loadee :)), but the framework complains that it can’t be found.

I’d be interested to try this project in MF3.0 and/or VS2008 to make sure nothing broke in 4.X. I won’t have time to try that out until later this evening.

That would be great, thanks, Chuckle.

Also, yes, my dev environment is VS 2010 Pro and .NETMF 4.1. Looking back, I shouldn’t have changed so soon, but VS 2008 Pro is already uninstalled.

Chris, this actually does work in VS2010/MF4.0. My configuration was screwed up, that’s why I got the errors. I had the dependent project’s target set to 4.1, but the loader project was targeted for 4.0. This bare-bones code will work if both assemblies are targeted for 4.0 (tested on EMX dev board, no cobra for me yet :frowning: ).

Dynamically loaded assembly, copied to SD after building (AsmToLoad.pe):


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;

namespace AsmToLoad
{
    public class WindowToLoad : Window
    {
        public WindowToLoad()
        {
            this.Height = SystemMetrics.ScreenHeight;
            this.Width = SystemMetrics.ScreenWidth;
            this.Background = new LinearGradientBrush(Colors.Black, Colors.Blue);
        }
    }
}

And the “loader” app code:


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using GHIElectronics.NETMF.IO;
using System.Reflection;
using System.IO;
using Microsoft.SPOT.IO;

namespace LoaderApp
{
    public class Program : Microsoft.SPOT.Application
    {
        public static void Main()
        {
            Program myApplication = new Program();

            Window mainWindow = myApplication.CreateWindow();

            // Create the object that configures the GPIO pins to buttons.
            GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);

            // Start the application
            myApplication.Run(mainWindow);
        }

        public Window CreateWindow()
        {
            using (PersistentStorage ps = new PersistentStorage("SD"))
            {
                ps.MountFileSystem();
                string sdDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;

                string asmPath = Path.Combine(
                    VolumeInfo.GetVolumes()[0].RootDirectory,
                    "AsmToLoad.pe");

                Assembly asmToLoad = Assembly.Load(File.ReadAllBytes(asmPath));
                return (Window)asmToLoad.GetType("AsmToLoad.WindowToLoad").GetConstructor(new Type[0]).Invoke(null);
            }
        }
    }
}

That works perfectly for me. Let me know if the same applies for you.

As a side note, I think this snippet from your original code may fail in MF:


_loaded = t.GetConstructor(null);

In the full .NET Framework world, we have to pass an empty Type array (or Types.Empty, which doesn’t exist in MF) to instantiate an object with a parameterless constructor. It looks like the same applies to MF.

Hi Chuckie,

I’ll play with this more a little later today. Maybe in another 3-4hrs or so.

Thanks for your work!

Also, I understand my code is probably flawed. At this point I just want to get a proof of concept going.

Believe me, I wasn’t trying to criticize the code by any means. Good luck with the Chumby clone :slight_smile:

Yep, no problem, I’m sure there’s lots to criticize in it though :wink:

I’m going to start playing with this in a minute…

It works!

So, now the next thing is to port my NTP clock over. If that works, then I’ll import the weather part too.