Подтвердить что ты не робот

Исходный отладочный веб-сайт BadImageFormatException, работающий в режиме x64

На этом форуме есть много вопросов о BadImageFormatException, но ни одна из них не соответствует моей проблеме.

У меня есть решение, содержащее несколько проектов. Когда я запускаю Debug или Release + Any CPU, все работает нормально. Однако, когда я переключаюсь на x64 и запускаю свой проект ASP.NET MVC, я получаю печально известный BadImageFormatException

Не удалось загрузить файл или сборку "AgileEFLib" или одну из его зависимостей. Была сделана попытка загрузить программу с неправильным форматом.

AgileEFLib - это внутренняя библиотека утилиты, поэтому у меня много гибкости. Но действительно странно, что когда я запускаю консольное приложение, которое также имеет зависимость от AgileEFLib, оно отлично работает. Единственный раз, когда он терпит неудачу, - это когда я запускаю веб-сайт.

Я проверил, что все проекты в конфигурации Release | x64 устанавливаются как x64.

Что еще можно сделать для устранения этого неполадки?

EDIT: Еще один полезный бит информации заключается в том, что эта проблема возникает только при отладке с помощью Visual Studio IIS Express. Когда я публикую и развертываю в IIS, он отлично работает.

EDIT: более подробная информация об ошибке:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not load file or assembly 'AgileEFLib' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.BadImageFormatException: Could not load file or assembly 'AgileEFLib' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'AgileEFLib' could not be loaded.



=== Pre-bind state information ===
LOG: DisplayName = AgileEFLib
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: AgileEFLib | Domain ID: 3
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/src/MyProject/
LOG: Initial PrivatePath = C:\src\MyProject\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\src\MyProject\web.config
LOG: Using host configuration file: C:\Users\Shaul\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/15406131/a0c36da/AgileEFLib.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/15406131/a0c36da/AgileEFLib/AgileEFLib.DLL.
LOG: Attempting download of new URL file:///C:/src/MyProject/bin/AgileEFLib.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
4b9b3361

Ответ 1

Попробуйте выполнить инструкции Отладка веб-сайтов VS2013 с использованием 64-разрядного IIS Express:

Если вы работаете на веб-сайтах ASP.NET MVC в Visual Studio 2013 (VS2013), вам нужно сделать одно изменение реестра, если вы хотите запустить IIS Экспресс как 64-битный процесс по умолчанию. Используйте один из методов, ниже.

из командной строки:

reg добавить HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects/v Use64BitIISExpress/t REG_DWORD/d 1

Ответ 2

Восстановите ссылочную сборку, используя настройку "AnyCPU". Это позволит помещать в него класс, содержащийся в 32-разрядном процессе или в 64-битном процессе.

Ответ 3

Вы можете использовать Fuselogvw.exe. Эта утилита сбрасывает всю активность Fusion в журнал. Затем вы можете просмотреть журнал и проверить, какая из DLL неправильного формата. Вы также должны увидеть, на что действительно зависит AgileEFLib. Возможно, сама DLL не проблема, а одна из ее зависимостей.

Я предполагаю, что одна из библиотек зависимостей на вашем сайте компилируется как x86.

Изменить: Также см. Уклонение зависимостей. Это показывает все зависимости и их архитектуру.