Main Site Documentation

ExtendedWeakReference on FEZ Spider


I just tried to use ExtendedWeakReference on a FEZ Spider (MF 4.2, Firmware 4.2.9) with the code given in the MF sample or I read in the forum. Unfortunately it doesn’t save anything. The target of ExtendedWeakReference.RecoverOrCreate(…) is always null. Is there anything to enable it?

Code - writing
var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);
ewr.Priority = (Int32)ExtendedWeakReference.PriorityLevel.Critical;
var numBoots = ewr.Target as NumBoots;
if (numBoots == null)
numBoots = new NumBoots(1);
numBoots.BootCount += 1;
ewr.Target = numBoots;

Code - reading
var ewr = ExtendedWeakReference.RecoverOrCreate(typeof(TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);
var numBoots = ewr.Target as NumBoots;
numBoots is always null!

Thanks for helping.


@ HBe - You need to use fully qualified type name as the type selector (name that includes namespaces).

See this thread:


Fully qualified type names help a littel bit, e.g. data will be kept as long the machine is running. But the data didn’t survive rebooting even I set the flag


I also was playing ouround with


Nothing helped. After rebooting (and deploying) the same code, the call


couldn’t recover the data. The code seems to be too easy to make any mistakes!

@ andre - thanks for the “101010” icon - I didn’t see it before…


No, this sample doesn’t work either. First I had to change the sample and use the fully qualified type. I could


the data until I rebooted the FEZ. Then everything was gone.
Thanks for your answer. I probably won’t use the flash memory, even if it would work, because as I understood the manual, it’s not guaranteed that the data would survive anyway. Probably it’s better to store data on a sd card.


@ HBe - as an alternative to using an SD card, you could use the Flash module.

If the raw access to this module does not suite you, there is also a file system driver available on code share


Hi HBe,

Have you been able to fix your problem with the writing of data on the Spider internal Flash memory ?

I do face the same problem. I used the code you talk about here and now with the latest version of the SDKs, nothing is stored in the Flash Memory, and the call to RecoverOrCreate always returns NULL.

Thanks for the feedback,



@ andre.m : Can’t remember where it comes from, it was last year when I started the project on NETMF 4.1. It was part of exchanges on the forum…

Could you point me to the code you use that works ?

Thanks Andre.


Got it. Thanks, Let me test that code, and verify mine. Stay tune :slight_smile:



OK. The demo code works also fine on my spider. So that means that it’s my code that does not work.

A couple of questions to figure out what’s going wrong :

  • How big can be the object that you put in Flash ? I actually put in a single classe all the configuration I need for my project. It’s more than a hundred parameters, mostly short strings

  • What exactly can be serialized and what cannot ? For example, can a DateTime object be serialized ?



The object that can be serialized for extended weak reference have the serializable attribute.

As an example, check the attribute for array list and hashtable int the system collection namespace.

How big can be the object… this is a real problem nobody can say how to compute the size of data that we can pass to EWR. However you can reduce size using [serializationhint].