corrupted resources in wince application using Compact Framework 3.5

106 Views Asked by At

I'm maintaining a windows ce form application developed on compact framework 3.5 The problem that i'm struggling with is that the application running on a windows ce 6.0 device after a few days of working crashes. It presents an exception:

SerializationException 255 at Systems.Resources.ResourceReader.ParseMessageEnd() at
System.Resources.ResourceReader.LoadBitmap(Int 32 typeIndex) etc

I've used then .Net Reflector to analyse the exe file that runs on the device and I found out that some resources are corrupted and they have a value: Invalid resource TypeCode '-1' and the type is System.BadImageFormatException, mscorlib, Veersion=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 whilst the non corrupted resources have Version=2.0.0.0

It's really strange how the files get corrupted and the version changes. I also found in the code a 200ms timer that runs forever and in that timer there was also this code which caused a lagging in the ui:

if (Global.ParSotteraneiQuadro.typepompa == ClParSottQuadro.EnTipoPompa.PNEUM)
        {
            ImagesMOTORE[0] = Resources.pump_OFF;
            ImagesMOTORE[1] = Resources.pump_OFF;
            ImagesMOTORE[2] = Resources.pump_ON;
            ImagesMOTORE[3] = Resources.pump_ON;

            btPompa.ImageBack = Resources.pump_OFF;
            btPompa.ImageFore = Resources.pump_ON;

            MemImageMOTORE = new ClassMemImage(ImagesMOTORE);

            ImagesTempWait[0] = Resources.anim12_230;
            ImagesTempWait[1] = Resources.anim22_230;
            ImagesTempWait[2] = Resources.anim32_230;
            ImagesTempWait[3] = Resources.anim42_230;
            ImagesTempWait[4] = Resources.sfondo_arancio; // arancione vuoto
            ImagesTempWait[5] = Resources.sfondo_red; // rosso vuoto
            ImagesTempWait[6] = Resources.warning_230;
            ImagesTempWait[7] = Resources.ok_230;
            ImagesTempWait[8] = Resources.eco_top;
            ImagesTempWait[9] = Resources.abil_pompa_pump;
            ImagesTempWait[10] = Resources.abil_24VOLT_sfumato;
            ImagesTempWait[11] = Resources.ok_230_giallo;

            MemImageWaitTemp = new ClassMemImage(ImagesTempWait);
        }
        else
        {
            ImagesMOTORE[0] = Resources.motor_OFF;
            ImagesMOTORE[1] = Resources.motor_OFF;
            ImagesMOTORE[2] = Resources.motor_ON;
            ImagesMOTORE[3] = Resources.motor_ON;

            btPompa.ImageBack = Resources.motor_OFF;
            btPompa.ImageFore = Resources.motor_ON;

            MemImageMOTORE = new ClassMemImage(ImagesMOTORE);

            ImagesTempWait[0] = Resources.anim12_230;
            ImagesTempWait[1] = Resources.anim22_230;
            ImagesTempWait[2] = Resources.anim32_230;
            ImagesTempWait[3] = Resources.anim42_230;
            ImagesTempWait[4] = Resources.sfondo_arancio; // arancione vuoto
            ImagesTempWait[5] = Resources.sfondo_red; // rosso vuoto
            ImagesTempWait[6] = Resources.warning_230;
            ImagesTempWait[7] = Resources.ok_230;
            ImagesTempWait[8] = Resources.eco_top;
            ImagesTempWait[9] = Resources.abil_pompa;
            ImagesTempWait[10] = Resources.abil_24VOLT_sfumato;
            ImagesTempWait[11] = Resources.ok_230_giallo;

            MemImageWaitTemp = new ClassMemImage(ImagesTempWait);
        }

Has someone faced something like this? Thank you for your help

2

There are 2 best solutions below

2
Valter Minute On

IIRC resources are loaded in writable memory, this means that application may overwrite that data if the pointers are used in the wrong way. Usually you don't access pointer directly in .NET, but those "Mem" classes may need some more investigation. And just a small not on performances, maybe all the assignments and allocations should be done only if Global.ParSotteraneiQuadro.typepompa has changed since the last check.

0
josef On

To autorun from external storage on insert:

"Auto-Run Applications on Compact Flash Cards Starting with Windows CE 3.0 it is possible to have an application run from a Compact Flash memory card when it is inserted into a device. This allows an application to auto-install from a Compact Flash card. To set an application to be auto-run, you must place the application in aspecific folder for the CPU targeted by your application. The folder name isbased on the CPU number returned in the dwProcessorType member of theSYSTEM_INFO structure returned from calling GetSystemInfo. Table 3.7 shows the possible values and their associated constants. Constant Value PROCESSOR_MIPS_R4000 4000 PROCESSOR_HITACHI_SH3 10003 PROCESSOR_HITACHI_SH3E 10004 PROCESSOR_HITACHI_SH4 10005 PROCESSOR_MOTOROLA_821 821 PROCESSOR_SHx_SH3 103 PROCESSOR_SHx_SH4 104 PROCESSOR_STRONGARM 2577 PROCESSOR_ARM720 1824 PROCESSOR_ARM820 2080 PROCESSOR_ARM920 2336 PROCESSOR_ARM_7TDMI 70001 Table 3.7. Processor values and associated constants Thus, if you want your application to auto-run and the application is compiled for MIPS, you should rename your application to autorun.exe and place it in a folder called \4000, for example, \4000\autorun.exe. If your application is compiled for CEF (Common Executable Format), you should place the autorun.exe file in a folder called \0, for example, \0\autorun.exe. The application autorun.exe is passed the command line parameter "install" when a Compact Flash card is inserted, and with the command line parameter "uninstall" when the card is removed. This allows your autorun.exe application to uninstall itself when the card is removed. ..." [From book: Windows CE 3.0 Application Programming]