2014-08-28 55 views
6

據我所知,這裏有很多這樣的帖子,我以前自己處理過這些,除了這一次沒有任何問題。這是因爲我無法從Windows Azure獲得所需的調試信息,並希望有人能夠幫助我。無法加載文件或程序集... Windows Azure網站

這個工作在我的本地環境中完全正常,調試&版本。

我收到此錯誤: 無法加載文件或程序集「Lib」或它的某個依賴項。試圖加載格式不正確的程序。

Lib確實存在於目錄中,它僅取決於System.Drawing & mscorlib。

通常我會附加到AppDomain.Current.AssemblyResolve或檢查異常時拋出。我無法使用Azure執行此操作,因爲預加載過程中發生異常。

[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& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 
    System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34 
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77 
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& 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& 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 

有沒有辦法重寫/創建自定義程序集加載器來截獲這個問題?

我完全喪失。

感謝

史蒂夫

回答

7

我討厭它,當我做到這一點。在SO上發佈一個問題,因爲我一整天都在嘗試,然後在10分鐘後修復它。

所以它似乎是我錯過了一個關鍵信息,這將幫助很多。

BadImageFormatException

這(據我可以告訴)被拋出當存在與所述平臺(體系結構)的兼容性(X86,X64)的問題。我所有的項目都是爲「任何CPU」編譯的(可以在項目屬性> Build> Platform Target,VS2013下找到)。

但是,我的「Lib」項目僅爲x64構建,Azure網站以32位模式運行,因此無法加載64位dll。

兩個選項:

  1. 編譯「庫」 DLL作爲AnyCPU位或32位,然後重新發布
  2. 開關蔚藍的網站,以64位。

我沒有選擇2,因爲什麼是「Lib」DLL我需要它作爲64位。

所以,以供將來參考,如果任何人有這樣的事情,檢查以下內容:

  1. Azure的網站平臺(下配置>平臺發現,在老門戶
  2. 檢查所有項目的設置爲任何CPU或兼容的「平臺(架構)」

我希望這可以幫助別人。

感謝

史蒂夫

編輯:如果其他人有一些有用的信息,其中可能有這個問題以後添加的人,請不要。

相關問題