views:

2527

answers:

2

I'm writing a C# application for a proprietary Windows CE 4.2 device (for which I don't have the specs or pretty much any other information. I've got access to the file system, and that is basically it.) I also can't get support from the original manufacturer.

Now, I can install the .NET Compact framework just fine, and everything works for a while. But every once in a while, when the device is reset, it deletes the framework, the GAC, everything related to it.

I know it's not just a hard reset jumping back to factory defaults because:

  1. It remembers the registry settings (If I try to install again, it says the framework is already installed, and asks if I want to reinstall. So obviously the registry keys are still there)
  2. The files are deleted even if I installed the framework onto a removable flash card. (Other files on the storage card are left alone, however)

I know there isn't much to go on, but perhaps some Windows CE guru will be able to tell me why this happens, and if there's some sane way to avoid it. I don't know much about Windows CE, so for all I know, it might be perfectly standard behavior.

For that matter, any advice on how to troubleshoot this further myself? At the moment, the best solution I can see is to simply reinstall everything at every boot, but that seems a bit clumsy.

Edit: After a reset, GACLOG.TXT found in the root of the filesystem contains

CGACUTIL: Initializing 12/08/2008

20:43:57.000 CGACUTIL: Initialized

12/08/2008 20:43:57.000 CGACUTIL:

Removing Microsoft .NET CF 3.5.GAC

12/08/2008 20:43:57.000 CGACUTIL: Done

12/08/2008 20:43:57.000 CGACUTIL:

Exiting 12/08/2008 20:43:57.000

So yeah, it's definitely deleting the GAC. Why though, and how to stop it?

A: 

I think you need to run RegSave to save the registry settings after installing something. I had to do this in an older (pre .Net) version of Windows CE.

Kosta
It's the other way around though. It saves the registry, but deletes the installed .dll's.
jalf
I see. In the old version that I worked with, everything would get deleted upon reboot. There was a specific folder where we would put the .cab file to reinstall the app. That's all I can remember.
Kosta
Right, but I dimly remember that you could also put dedab'd files in that folder. Find one where other files persisted through reboot. Folders don't mean what you think they mean. Hierarchies aren't really hierarchies. All for the faux "rich windows experience".
le dorfier
Updated my question a bit. It's clear that the device storage is not just being reset. It's actually running cgacutil to remove the GAC manually.Thanks for the suggestions so far though. (By the way, what do you mean by dedab'd files?
jalf
Meant "decab'd - removed from cabs.
le dorfier
+6  A: 

There are a few Windows CE and CF behaviors that you're seeing here that's giving you this behavior. Unfortuantely there's no really good solution, but I can at least give you some guidance.

  1. Windows CE stores the current object store, including files in the filesystem not specifically on a persistent store in RAM. This includes any files and/or folders added to the \Windows folder (this is key in your case). When device power is lost - typically in a soft or hard reset, this data is lost.
  2. The CE registry can (and probably is on your device) be stored on a persistent store. This might be in the file system (as a hive) or in some non-visible location (there are two distinct ways an OEM can store it). This is not lost on reset. Only items saved and not flushed are lost.
  3. As an addendum to #2 - the registry changes are flushed when the RegFlushKey API is called. Installing a CAB automatically calls this (so installing the CF does). Some OEMs also choose to have it flush on a periodic timer.
  4. When the CF GACs an items not in the image, the file is moved to the \Windows folder. They are put back when the assembly is unloaded (I complained to the CF team about this years ago to no avail).

What this means is that if you install the CF to a storage card and run your app this happens:

  1. CF files are copied to the persistent store during unpacking the CAB
  2. Installation reg keys are written
  3. Registry is flushed (saved)
  4. App runs
  5. CF files are moved (not copied) to \Windows, which is volatile.

Now if you reset the device while the CF assemblies are loaded - poof! no more CF. Your app was on the storage card, but not in the GAC, so it survives but can no longer run.

A hack solution: use a native app to "bootstrap" to launch your app. Have it check for the CF files in \Windows on run and if they aren't there install the CF CAB from a place in persistent storage (mark it as read-only so wceload won't delete it).

The other option is to distribute the CF assemblies with your app and not GAC them.

ctacke
Thanks. Extremely helpful. I'll give this a shot at work tomorrow, but it sounds like you've nailed it (and like you've been bitten by this before ;))
jalf
Aye the former is what I usually go for with a different bootstrap depending on the device. What I never understand though is why some devices don't listen to /silent or /noui or whatever combination I provide. For one I had to (ewwww) send keys to reinstall on cold boot and kiosk the device.
Quibblesome
Don't even get me started on that piece of @%$# wceload. That's why I wrote our CAB installer SDK - so you can unpack a CAB yourself and have complete control over the installation.
ctacke

related questions