One of the coolest new features in v2 is the ability to diagnose problems through the new logging infrastructure.  With the new Windows Mobile 5.0 security model, loader problems can be hard to find and figure out.  If you have an app that just won't start and you can't figure out why, the following steps might help you locate the problem:

Enable loader logging.

There are two registry keys you need to enable:
HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Enabled (DWORD) -> 1
HKLM\Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Loader\Enabled (DWORD) -> 1

Look for application load errors.

There should be a line in the netcf_Loader.log file that looks like this:

Loading module [\application.exe]

And it should be followed by something that looks like this:

Trust verification passed. Module [\application.exe], Trust [1], Proc [1].

Ignoring all the incomprehensible stuff, the key here is that it says "Trust verification passed."  That's good and it means your application passed the security check.  Anything else means that your application is not trusted by the underlying platform--there are a number of different reasons this could be the case (check out my earlier article).

Look for assembly load errors.

These can be a bit trickier.  Again, the log file gives you all sorts of useful information--the main one being the trust verification message above.  But now it's possible that your assembly is signed, but can't be loaded into the application because its trust level doesn't match that of the application.  If this sounds confusing, don't worry, it is.  Take a look at my article for some background.  This is what the log file tells you when this happens:

Trust verification failed. Module [\HelperDLL.dll], Trust [1], Proc [2].

What does this actually say?  The assembly HelperDLL.dll was assigned a trust level of 1.  There's a rule in Windows Mobile security that any code loaded into a process must at least have the trust level of the process.  In this case, the process trust level is 2 and the assembly's trust level is 1--the assembly doesn't have enough privilege to run in a level 2 process.

Make sense?!  The loader log has all sorts of other useful information as well.  We also have Interop and Network logging.  Steven's blog is a good place to start for all sorts of logging information.

Cheers,

Ryan