46

C++ ライブラリといくつかの dll を使用する c# のプロジェクトがあります。私がそれを実行すると、うまくいきます。

ライブラリはAwesomiumで、c++ ライブラリと c# ラッパーの両方が含まれています

ASP.NET MVC 4 プロジェクトからこのプロジェクトへの参照を作成すると、次のエラーが発生します。

例外の詳細: System.BadImageFormatException: ファイルまたはアセンブリ 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' またはその依存関係の 1 つを読み込めませんでした。モジュールには、アセンブリ マニフェストが含まれている必要がありました。

私が試したこと:

  1. dll をコピーしますが、まだ機能しません (ファイルが存在します)。

  2. GACに登録していますが、同じエラーが発生しました。

  3. .NET Framework 4.0 を使用していることを確認してください (クライアント プロファイルではありません)。

  4. 競合を引き起こす同じ dll/exe 名の 2 つのファイル- 私はそれを持っていません。

  5. ソリューションのプラットフォームを 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
4

8 に答える 8

41

ターゲットの .NET Framework とは異なる InstallUtil を使用していることがわかりました。.NET Framework 4.5 をビルドしていますが、.NET Framework 2.0 リリースを使用している場合、エラーが発生しました。ターゲットの .NET Framework に適切な InstallUtil を使用して、この問題を解決しました!

于 2013-01-22T10:46:34.200 に答える
13

BadImageFormatException、私の経験では、ほとんどの場合、x86 と x64 でコンパイルされたアセンブリに関係しています。C++ アセンブリが x86 用にコンパイルされ、x64 プロセスで実行されているようです。あれは正しいですか?

AnyCPU/Mixedプラットフォームとして使用する代わりに。手動で設定してx86、その後実行されるかどうかを確認してください。

于 2012-09-01T10:49:45.487 に答える
1

マニフェストが有効な xml ファイルかどうかを確認してください。ビルドの最後に DOS コピー コマンドを実行して同じ問題が発生しましたが、何らかの理由で "コピー" がマニフェスト ファイルの最後に奇妙な文字 (->) を追加していたことを理解できませんでした。この問題は、「/b」スイッチを追加してバイナリ コピーを強制することで解決されました。

于 2016-08-25T09:41:48.173 に答える