G120 EWR 'corrupt' after PushBackIntoRecoverList

I’m having an issue with EWR after a call to PushBackIntoRecoverList(). To demonstrate it, Run the app from the debugger with a breakpoint at the while() statement in main()…At the first run, data is created in EWR, restart the debugger, data is loaded as expected, Run debug a 3rd time and data is created new again. Sometimes a 3rd debug session will not reach main and hangs in GC: performing heap compaction…and even sometimes when the system hangs in heap compaction the my WIn7/32bit windows desktop crashes with a BSOD

It seems that PushBackIntoRecoverList()… corrupts memory


using System;
using GHI.Premium.System;
using Microsoft.SPOT;

namespace G120EWR
{
    public class Program
    {
        private static readonly Configuration Config = new Configuration();

        public static void Main()
        {
            Debug.Print("EWR test start");

            // Place a breakpoint here and restart a debug session.
            while (true)
            {}
        }
    }

    public sealed class Configuration
    {
        private static ExtendedWeakReference _settingsReference;
        internal AppSettings Settings = new AppSettings();

        public Configuration()
        {
            _settingsReference = ExtendedWeakReference.RecoverOrCreate(typeof (AppSettings), 0,
                                                                       ExtendedWeakReference.c_SurviveBoot |
                                                                       ExtendedWeakReference.c_SurvivePowerdown);
            _settingsReference.Priority = (int) ExtendedWeakReference.PriorityLevel.System;
            Settings = _settingsReference.Target as AppSettings;
            if (Settings == null)
            {
                // Must be a first time init
                Settings = new AppSettings();
                _settingsReference.Target = Settings;
                Util.FlushExtendedWeakReferences();
                Debug.Print("New configuration, defaults saved");
            }
            else
            {
                // -------------------------------------------------
                // !!! EWR destroyed when next method "PushBackIntoRecoverList" is called  !!!
                // -------------------------------------------------
                _settingsReference.PushBackIntoRecoverList();
                Debug.Print("Configuration loaded");
            }
        }

        public void Save()
        {
            _settingsReference.Target = Settings;
            Util.FlushExtendedWeakReferences();
        }
    }

    [Serializable]
    internal sealed class AppSettings
    {
        public string SomeConfigData = "just some text";
    }
}

while (true)
{
}

is bad, mkay.

thread.sleep(timeout.infinite);

@ Brett - In this example its just to set a breakpoint at that line… could also be the thread.sleep…

EWR flushes data on idle so the while loop will be a problem.

@ Gus - Ok, i believe that, but i guess thats not a justification for what happens at the 3rd debug try.

try debugging it again with the thread.sleep in there to ensure the behavior isn’t being affected by a BAD thing (and one your real app should never hit)

@ Brett - as suggested by you, i replaced the while loop with the thread.sleep. Unfortunately and as expected it didn’t change the behavior.

@ Gus - This is a serious BUG :frowning: I start to feel like a beta tester for the G120 module…

We will double check on our end and hopefully get it out in this same SDK coming out in a week or two.

Hi Gus, any update on this issue?

We did some testing on this and we are not seeing any errors in our drivers. What we learned is that on 4.2, using PushBackIntoRecoverList in debugging will always wipe out the data on the next deployment but this works fine if the device run stand alone.

One way to handle this would be by using EWR the same way it is in this example C:\Users\Dat\Documents\Microsoft .NET Micro Framework 4.2\Samples\ExtendedWeakReferences

Your code works fine if you change it like the example code above and not use PushBackIntoRecoverList