Question

I am working on a C# code running on .NETCF 3.5 on WindowsCE 6.0 that is throwing MissingMethodExceptions for Func`2<> during runtime. The code parts where the exception occurs is random.

The weird thing is, this happens when you already use the application for a while AND where definitely many calls to Func`2 already happened. (eg. via IEnumerable.Select() or .Where()) It seems that this behaviour starts if you just load enough Types during the lifetime of the application such that the sum of assembly file sizes exceeds ~18MB. But there is enough memory (RAM) available on the device to load the Type.

Also activated LoaderLogging but to no avail. It only shows me a TypeLoad error for Func`2.

As I ran out of ideas: What could be the cause of such errors?

Unfortunately I cannot share any code because it is 1) property of the company I work for and 2) many ten-thousand lines of code.

Was it helpful?

Solution

It seems there is a limit on .NETCF:

One can only construct 1024 unique closed types per generic type declaration. (For more information see section "Limitations": http://blogs.msdn.com/b/romanbat/archive/2005/01/06/348114.aspx)

Meaning:

List<int> a;
List<int> b;
List<int> c;

takes one "slot",

List<int> d;
List<string> e;

takes two "slots" (two unique closings), and so on.

Tricky thing was: Usually this raises an ArgumentException, but sometimes .NETCF throws MissingMethodExceptions instead. (see "3. Differences in exceptions thrown.": http://blogs.msdn.com/b/nazimms/archive/2005/01/25/360324.aspx)

We reduced the usings of Func`2 by using our own Delegate Types where possible and this has solved the problem.

OTHER TIPS

you already answered your question yourself, if you know the backgrounds of Windows CE memory management: "...such that the sum of assembly file sizes exceeds ~18MB. But there is enough memory (RAM) available on the device to load the Type...."

You know, that every process only gets a 32MB program memory slot, regardless of having a GB RAM or more! That is by design. You know, that DLLs loaded by your or any other running process are loaded into the 32MB slot of EVERY process (although there are not loaded with there full size with Windows Embedded Handheld 6.5). So the more DLLs are loaded, a process gets less available program memory. See also http://community.intermec.com/t5/General-Development-Developer/Slaying-the-virtual-memory-monster/m-p/16764 for more details.

If the process memory, which growing from bottom of 32MB slot, grows against the loaded DLLs, which are loaded from top of 32MB slot, you will get strange program behaviours or even crashes.

The above is valid for all Windows CE 5 based OS versions like windows Mobile 6.1, Windows Mobile 5 or even the latest Windows Mobile 6.5.3 (Embedded Handheld). The above has to be revised for Windows CE 6 based OS versions.

regards

Josef

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top