title: Windows Mobile 6.5 - TypeLoadException on Process.Start()
body: <p>In the solution I have several <code>.exe</code> files that sit in the same directory. One of them is a Master Menu, which looks up all the other executables' path (within the same dir) and assigns to buttons in the form. When the button is clicked it's underlying exe is launched via <code>Process.Start()</code>.</p>
  
  <p>Each <code>exe</code> is packed in separate installation CAB. After initial install, I run the Master Menu, then pick any of the buttons and underlying app launches successfully. I quit it, then run again the same or any other app but this time it crashes with:</p>
  
  <pre><code>TypeLoadException
     at System.Windows.Forms.Control.OnGotFocus(EventArgs e)
     at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
     at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
     at Microsoft.AGL.Forms.WL.SetFocus(IntPtr hwnFocus)
     at System.Windows.Forms.Control.Focus()
     at myApp.Login..ctor()
     at myApp.Form_UnderApp1.InitializeComponent()
     at myApp.Form_UnderApp1..ctor()
     at myApp.Program.Main()
  </code></pre>
  
  <p><code>myApp.Login</code> is an UserControl which has <code>TextBox.Focus()</code> in its constructor. I tried to move it out to 'Validated' event handler but the outcome is the same, with one difference that this time it crashes on <code>Form.Load()</code> when trying to set its own visibility.</p>
  
  <p>The cycle can be repeated after device reset. Most importantly, if I run any of the child executables directly those launch and work fine all the time.</p>
  
  <p>The same code set works fine on WinMo 6.1. I also use OpenNETCF's <code>Application2</code> class - tried to replace it with standard <code>Application</code> class with the same result. Tried to set <code>Process.StartInfo.WorkingDirectory</code> and <code>UseShellExecute</code> but again no joy. When looking at <code>Process()</code> object in the "Master Menu" app - it behaves as expected (creates process, returns 'true' on <code>.Start()</code> etc).</p>
  
  <p>No assemblies are installed to GAC, all files reside in the same dir.</p>
  
  <p>Any clues?</p>
  
  <p>[Edit]</p>
  
  <p>After I get the error and device is left untouched for about 10 minutes it all gets back to start: I can again run sub-app once etc.
  Giving that I tried wiping reference to current process from my Master Menu, killing the process, calling <code>GC.Collect()</code> with no result.</p>
  
  <p>[Edit]</p>
  
  <p>Loader log looks ok up to this point (this is where app starts failing):</p>
  
  <pre><code>Redirecting [Microsoft.WindowsCE.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC] to [Microsoft.WindowsCE.Forms, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC]
  Loading module [\windows\GAC_Microsoft.WindowsCE.Forms_v3_5_0_0_cneutral_1.dll]
  Loaded [Microsoft.WindowsCE.Forms, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC] from [\windows\GAC_Microsoft.WindowsCE.Forms_v3_5_0_0_cneutral_1.dll]
  Loading module [\Program Files\MyApp\System.SR.dll]
  Attempt to load [\Program Files\MyApp\System.SR.dll] has failed (err 0x80001000).
  Loading module [\Program Files\MyApp\System.SR.exe]
  Attempt to load [\Program Files\MyApp\System.SR.exe] has failed (err 0x80001000).
  Loading module [\windows\System.SR.dll]
  Attempt to load [\windows\System.SR.dll] has failed (err 0x80001000).
  Loading module [\windows\System.SR.exe]
  Attempt to load [\windows\System.SR.exe] has failed (err 0x80001000).
  Failed to load [System.SR, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC]
  </code></pre>
  
  <p>After copying <code>System.SR.dll</code> to app installdir:</p>
  
  <pre><code>Loading module [\windows\en\System.SR.resources.dll]
  Attempt to load [\windows\en\System.SR.resources.dll] has failed (err 0x80001001)
  </code></pre>
  
  <p>Installed <code>System_SR_ENU.CAB</code> and <code>NETCFv2.wm.armv4i.cab</code> but now log says that one of the device specific dlls (<code>ITCScan.DLL</code>) can't be loaded, which I believe to be .NET 3.5 assembly.
  As far as I know <code>System.SR</code> is used only in .NET2, is it not that some other exception is trying to surface and manifests itself like this?</p>