.NET CF Type Load Exception

I received confirmation this morning that an exception I was getting in the application we are building was not a result of our achitecture, but rather a bug in the .NET CF type loader.  Get this though – in order to recreate the exception you have to write some pretty obscure:

Assembly A:

class Foo {}

class Bar<T> {

    T field;


Assembly B:

struct MyValueType{} //has to be user-defined valuetype i.e. struct, enum…

class Child : Foo {}

class MyClass {

    Child c;

    Bar<MyValueType> b;


“.NetCF will fail to load MyClass if MyValueType hasn’t been preloaded. The workaround is to pre-load the valuetype  (i..e. use it somewhere in the code before MyClass is first referenced).

The problem exists in the .NetCF v2 SP1. We fixed it for the next version of the .NetCF, the fix may also be rolled into next service release of .NetCF v2.”  [taken from an email from Roman Batourkov]

Leave a comment