2012-09-01 38 views
27

我有一個項目在C#中使用C++庫和一些DLL。當我運行它的時候效果很好。該模塊預計包含程序集清單

圖書館是Awesomium,同時包含C++庫和C#包裝

當我創建引用從我的ASP.NET MVC 4項目這個項目中,我得到以下錯誤:

異常詳細信息: System.BadImageFormatException:無法加載文件或程序集'file:/// D:\ Projects \ Development \ ProGamers \ GamingSite \ bin \ avcodec-52.dll'或其某個依賴項。預計該模塊將包含程序集清單。

事情我已經嘗試:

  1. 應對的dll文件,但它仍然無法正常工作(該文件存在)。

  2. 在GAC中註冊它,但我在那裏有同樣的錯誤。

  3. 確保使用.NET Framework 4.0(而不是客戶端配置文件)

  4. 2 files with the same dll/exe name causing conflict - 我沒有它。

  5. Change the platform of the solution to AnyCPU/Mixed Platforms。

堆棧跟蹤:

[BadImageFormatException: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest.] 
    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.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102 
    System.Reflection.Assembly.LoadFrom(String assemblyFile) +34 
    WebActivator.ActivationManager.Run() +190 

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90 
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +135 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516 

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9850940 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 
    System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456 
+0

你能從[Assembly Binding log viewer](http://msdn.microsoft.com/en-us/library/e74a18c4.aspx)的綁定中獲得日誌嗎?確保首先將設置設置爲「記錄所有綁定」。 – rene

+0

Assembly.LoadFrom()不能在像avcodec-52.dll這樣的DLL上工作,它不是.NET程序集。爲什麼你的代碼試圖像這樣加載它是完全不清楚的,如果你不發佈一個片段。 –

+0

漢斯我沒有手動使用程序集,它在控制檯應用程序中運行良好。只有當我從ASP.NET應用程序引用它時,它纔會產生問題。 而我唯一使用的是引用Awesomium dll。 http://awesomium.com –

回答

7

BadImageFormatException,以我的經驗,幾乎總是使用x86與x64的編譯的程序做的。這聽起來像你的C++程序集是爲x86編譯的,而且你正在運行一個x64進程。那是對的嗎?

而不是使用AnyCPU/Mixed作爲平臺。嘗試手動將其設置爲x86並查看它是否會在此之後運行。

希望這會有所幫助。

+1

我的機器是x86,C++程序集也可能是x86。 我試着手動將這兩個項目設置爲x86,但它沒有工作.. –

+0

這解決了我的問題。顯然,我的程序集是爲x86編譯的,它不喜歡在x64項目中編譯。 –

33

我發現,我從我的目標.NET Framework中使用了不同的InstallUtil。我正在構建.NET Framework 4.5,與此同時,如果我使用.NET Framework 2.0版本,則會發生錯誤。爲我的目標.NET Framework使用正確的InstallUtil,解決了這個問題!

1

我發現了另一個奇怪的原因,我想可能是另一個開發者混淆爲我。我確實運行了install.bat,該安裝程序創建用於安裝我的服務VS2010的開發者命令提示符,但我的服務在VS2012中生成。它是去這個錯誤,並促使我瘋了,但我嘗試VS2012開發人員命令提示工具和一切都沒有問題。我不是沒有爲什麼,但我的問題解決了。所以你可以測試它,如果有人知道原因,請與我們分享。謝謝。

1

檢查清單是否是有效的xml文件。我在構建結束時通過執行DOS複製命令也遇到了同樣的問題,結果出於某種原因,我無法理解「複製」是在清單文件的末尾添加了一個奇怪的字符( - >)。通過添加「/ b」開關強制二進制副本解決了該問題。

1

首先嚐試用反編譯器(如ILSpy)打開文件,您的dll可能已損壞。我在一個在線網站上有這個錯誤,當我下載DLL並試圖打開它時,它已經損壞,可能在通過FTP上傳時發生了一些錯誤。

相關問題