Исходное название: Как я могу предотвратить загрузку родной DLL из приложения .NET?
Фон:
Приложение My С# включает в себя плагин и общий плагин-загрузчик.
Плагин-загрузчик перечисляет каталог приложения для идентификации плагинов-плагинов (по существу он ищет *.dll в это время).
Внутри того же каталога приложений есть родная (Windows, non.net) dll, которая, косвенно, зависит от одной из плагинов плагина.
Плагин-загрузчик слепо предполагает, что native.dll - это сборка .NET Assembly, просто потому, что он проверяет только расширение файла. Когда он пытается загрузить собственную DLL, генерируется исключение:
"Не удалось загрузить файл или сборку" native.dll "или одну из его зависимостей. Ожидается, что модуль будет содержать манифест сборки.
Я в основном создаю диагностический отчет, если загрузка плагинов не удалась, поэтому я стараюсь, чтобы этот журнал не заполнялся сообщениями о невозможности загрузки родной DLL (чего я даже не хочу пытаться).
Вопрос:
Есть ли какой-нибудь вызов .NET API, который я могу использовать, чтобы определить, является ли бинарный файл сборкой .NET, чтобы я вообще не пытался загружать собственную DLL?
Возможно, более продолжительный срок я переведу мои плагины в подкаталог, но пока я просто хочу, чтобы работа вокруг не включала жесткое кодирование имени native.dll внутри моего загрузчика плагинов.
Я предполагаю, что я ищу какой-то статический API-интерфейс Assembly.IsManaged(), который я упустил. Предположительно, такой API не существует?