Main Site Documentation

Error in IntializeModules() - Modules must be created on program's dispatcher thread


#1

Hi all,

For some reason I’ve got a problem with my program suddenly. It has been happily deploying for the last few days and I’ve just been adding new code/rewriting some old code etc.

But now, when I try and run my program I get:

[quote]An unhandled exception of type ‘System.Exception’ occurred in Gadgeteer.dll

Additional information: Modules must be created on the Program’s Dispatcher thread[/quote]

This happens inside IntializeModules() in Program.generated.cs. I’ve tried commenting out some of initialize modules lines such as:



but it just fails on the next module's intialize line.

I have never touched anything in Program.generated.cs so I don't know how this has started.

Anybody have any ideas?

Thanks

#2

Unusual.

Have you change any code that does something with threads?


#3

No, I searched the project too for the phrases “Threading” “System.Threading” etc. just to see if I had put a Sleep() statement somewhere or other in a moment of madness but no not that I can find.

I just have the usual:

Program.Mainboard = new GHIElectronics.Gadgeteer.FEZCerberus();
            Program p = new Program();
            p.InitializeModules();
            p.ProgramStarted();
            // Starts Dispatcher
            p.Run();

And InitializeModules() just does initialize modules so I can’t find where it’s creating another thread or switching to another thread etc.


#4

What modules are you using?
Can you post a screen shot of the exception output in the debug window?


#5

Hi I am using:

SDCard
Display_HD44780
Keypad_KP16
2 Multicolor LEDs

The weird thing is this project has been working fine for the last month and only yesterday started giving me this exception.

As requested I’ve attached a screenshot.


#6

Something seems very strange there. Can you check the netmf target is set to the USB and your Gadgeteer device? (I am wondering if somehow it’s trying to target the emulator)


#7

Still the USB device as it was before.

I tried switching it over the Emulator then back to USB just to make sure but still getting the same problem.

Here is the Output dump if it is useful:

[quote]Found debugger!

Create TS.

Loading start at 8052594, end 807c914

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Hardware (4.2.0.0)
Assembly: Microsoft.SPOT.Graphics (4.2.0.0) Assembly: Microsoft.SPOT.TinyCore (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0) Assembly: Microsoft.SPOT.IO (4.2.0.0)
Assembly: System.IO (4.2.0.0) Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0) Assembly: System.Xml (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1) Assembly: Microsoft.SPOT.Net (4.2.0.0)
Assembly: System (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: GTM.GHIElectronics.Display_HD44780 (4.2.100.0) Attaching deployed file.

Assembly: GHI.OSHW.Hardware (4.2.6.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.SDCard (4.2.100.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCerberus (4.2.100.0) Attaching deployed file.

Assembly: Gadgeteer.Serial (2.42.0.0) Attaching deployed file.

Assembly: GadgeteerApp14 (1.0.0.0) Attaching deployed file.

Assembly: Gadgeteer.DaisyLink (2.42.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.Keypad_KP16 (4.2.100.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.MulticolorLed (4.2.100.0) Resolving.

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.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\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.2\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.OneWire.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\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.2\Assemblies\le\System.Xml.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\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.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Display_HD44780\NETMF 4.2\le\GTM.GHIElectronics.Display_HD44780.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI OSHW NETMF v4.2 SDK\Assemblies\le\GHI.OSHW.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\SDCard\NETMF 4.2\le\GTM.GHIElectronics.SDCard.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Mainboards\FEZCerberus\NETMF 4.2\le\GHIElectronics.Gadgeteer.FEZCerberus.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.Serial.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Keypad_KP16\NETMF 4.2\le\GTM.GHIElectronics.Keypad_KP16.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.DaisyLink.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\MulticolorLed\NETMF 4.2\le\GTM.GHIElectronics.MulticolorLed.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Users\Thomas\Documents\Visual Studio 2012\Projects\GadgeteerApp14\GadgeteerApp14\bin\Debug\le\GadgeteerApp14.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZCerberus version 1.1
A first chance exception of type ‘System.Exception’ occurred in Gadgeteer.dll
An unhandled exception of type ‘System.Exception’ occurred in Gadgeteer.dll
Additional information: Modules must be created on the Program’s Dispatcher thread
The program ‘[1] Micro Framework application: Managed’ has exited with code 0 (0x0).[/quote]


#8

@ Poncho - Did you installed latest SDK (R3) very recently by any chance? (I know, the output shows previous version).

If you didn’t I recommend to do that.


#9

I think this might be a clue.


#10

@ Architect - Hi, I installed the newest version (4.3) but when I first started this project it said I had to use 4.2 to use some of the modules I was using (not sure which ones).

If I now try and change the Target Framework to 4.3 I get errors saying that the modules can only be used on 4.2.

My program.cs is very short, I tried to cut everything out but it still doesn’t deploy at this point (so my ProgramStarted() is currently empty).

Here is my program.generated.cs:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.34003
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace GadgeteerApp14 {
    using Gadgeteer;
    using GTM = Gadgeteer.Modules;
    
    
    public partial class Program : Gadgeteer.Program {
        
        /// <summary>The SDCard module using socket 7 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.SDCard sdCard;
        
        /// <summary>The Char_Display module using socket 4 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.Display_HD44780 char_Display;
        
        /// <summary>The Keypad KP16 module using socket 3 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.Keypad_KP16 keypad_KP16;
        
        /// <summary>The MulticolorLed module using socket 6 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.MulticolorLed lightNewMessage;
        
        /// <summary>The MulticolorLed module using socket * of lightNewMessage.</summary>
        private Gadgeteer.Modules.GHIElectronics.MulticolorLed lightMessagesFull;
        
        /// <summary>This property provides access to the Mainboard API. This is normally not necessary for an end user program.</summary>
        protected new static GHIElectronics.Gadgeteer.FEZCerberus Mainboard {
            get {
                return ((GHIElectronics.Gadgeteer.FEZCerberus)(Gadgeteer.Program.Mainboard));
            }
            set {
                Gadgeteer.Program.Mainboard = value;
            }
        }
        
        /// <summary>This method runs automatically when the device is powered, and calls ProgramStarted.</summary>
        public static void Main() {
            // Important to initialize the Mainboard first
            Program.Mainboard = new GHIElectronics.Gadgeteer.FEZCerberus();
            Program p = new Program();
            p.InitializeModules();
            p.ProgramStarted();
            // Starts Dispatcher
            p.Run();
        }
        
        private void InitializeModules() {
            this.sdCard = new GTM.GHIElectronics.SDCard(7);
            this.char_Display = new GTM.GHIElectronics.Display_HD44780(4);
            this.keypad_KP16 = new GTM.GHIElectronics.Keypad_KP16(3);
            this.lightNewMessage = new GTM.GHIElectronics.MulticolorLed(6);
            this.lightMessagesFull = new GTM.GHIElectronics.MulticolorLed(this.lightNewMessage.DaisyLinkSocketNumber);
        }
    }
}


#11

You do need to use 4.2.

But the problem is that your app still uses assemblies from the previous version (R2).

Try to create the project from scratch or rip off all references and re-add them.

Edit:

See how version is 4.2.100.0 in the output below:

With the latest SDK (R3) it should be 4.2.101.0

Also make sure to update the firmware on the device as well (so it matches the installed SDK)


#12

Ah okay thanks.

I’ll try creating a new project and copy/pasting the code over and report back.


#13

Okay creating a new project and copying everything over seems to have worked but the deploy output still says:

4.2.100 not 4.2.101 but it seems to be running.

How would I get it to work on 4.2.101? I’ve got the newest version of gadgeteer and the ghi package downloaded and installed.


#14

Did you uninstall the previous one before installing the latest?
Did you update the firmware on the device?


#15

Yes I did a clean install of gadgeteer making sure all .net micro stuff was uninstalled as well etc.

And yes the Cerberus has the newest firmware on using the new firmware updater.


#16

Hmmm. Something is not right. I have updated recently and it shows 101 for that module for me (see the picture).

I would try to uninstall everything GHI and reinstall the R3 again.


#17

Hmm okay I’ll try that again thanks.

What updater do you use for the Cerberus? I remember seeing a new beta version kicking around somewhere but can’t find it again.

Thanks.


#18

the R3 SDK release from GHI contains the released version of the updater, no longer a beta.


#19

@ Poncho - I have used the one that came with the R3 SDK as @ Brett kindly pointed out earlier.


#20

Thanks Brett and Architect I’ll try getting up-to-date today!

Also, I found where the error was about the Dispatcher thread: I was initializing a static GT.Timer in the class like so:

static class Foo
    {
        private static GT.GHIElectronics.Display_HD44780 CharDisplay;
        private static string topLine = "";
        private static string bottomLine = "";

        private static Gadgeteer.Timer timer = new Gadgeteer.Timer(0, Gadgeteer.Timer.BehaviorType.RunOnce);

Rather than inside a function and so it was shouting at me for doing so.

It would be nice if the error could be a bit more descriptive though, because the way it was written I immediately thought it was something to do with the module creation/initialization.

Thanks again for all the help and I hope this will help people with the same problem in the future!

Poncho