title: Could not load file or assembly... Windows Azure Website
body: <p>I understand there is lots of these posts around and I've dealt with these on my own before with no problem except this time. It's because I can't get the debug information i need out of Windows Azure and hoping someone might be able to help me out.</p>
  
  <p>This all work's perfectly fine in my local environment, debug &amp; release.</p>
  
  <p>I'm getting this error:
  Could not load file or assembly 'Lib' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p>
  
  <p>Lib does exist in the directory, it depends on only System.Drawing &amp; mscorlib.</p>
  
  <p>Usually I would just attached to <code>AppDomain.Current.AssemblyResolve</code> or check the exception when it's throw. I'm not able to do this with Azure because the exception happens during the preload stuff.</p>
  
  <pre><code>    [BadImageFormatException: Could not load file or assembly 'Lib' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
     System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
     System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
     System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
     System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
     System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean forIntrospection) +16
     System.Reflection.Assembly.Load(String assemblyString) +28
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
  
  [ConfigurationErrorsException: Could not load file or assembly 'Lib' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +736
     System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
     System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
     System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
     System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
     System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean&amp; isRefAssemblyLoaded) +284
     System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
     System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521
  
  [HttpException (0x80004005): Could not load file or assembly 'Lib' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
  </code></pre>
  
  <p>Is there a way to override / create custom assembly loader to intercept this problem?</p>
  
  <p>I'm at a complete loss.</p>
  
  <p>Thanks</p>
  
  <p>Steve</p>