title: Help on TypeLoadException
body: <p>I'm writing a .NET 3.5 application (WinForms) which uses classes from an external DLL and I keep receiving a <code>System.TypeLoadException</code> every time the application tries to start.<br>
  Here is the exception VS displays:</p>
  
  <pre>
  System.TypeLoadException was unhandled
    Message=Could not load type 'PolyMorph.Common.Settings' from assembly 'PolyMorph, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    Source=PolyMorph
    TypeName=PolyMorph.Common.Settings
    StackTrace:
         at PolyMorphApp.App.Initialize()
         at PolyMorphApp.App.Main()
         at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: 
  </pre>
  
  <p>Here is the code that I'm running:</p>
  
  <pre><code>Friend NotInheritable Class App
  
      &lt;STAThread()&gt; Shared Sub Main()
          'set the exception handlers'
          Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
          AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
          AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
          'initialize the application'
          App.Initialize()
  
          'and then run the application'
          Dim mainForm As New PolymorphHost
          Application.Run(mainForm)
      End Sub
  
      Shared Function Initialize() As FunctionResult
          If App.InitializeDataDirectory() = False Then
              Return New FunctionResult(False, "the application's data directory")
          End If
  
  
          _settings = New PolyMorph.Common.Settings(AppDataDirectory &amp; "\Settings.dat")
          ......code continues to load settings from the _settings variable
      End Function
  End Class
  </code></pre>
  
  <p><br/><br/>
  What surprises me is that the VS2010 Debugger stops on the line <code>App.Initialize()</code> without even stepping into the <code>Initialize</code> function.</p>
  
  <p>If, however, I comment out all references to the external DLL in the <code>Initialize</code> function, the application initializes properly.</p>
  
  <hr>
  
  <p>After reading around, I realized that a number of people reporting this error were using different builds on their projects (as in x64 DLL being referenced from an x86 application). I therefore changed the build configuration so the DLL and the application were both x86 but I still have the <code>TypeLoadException</code>.</p>
  
  <p>Is there anything I'm missing?</p>