Inspect dependencies for dynamically loaded library in .net core

孤人 提交于 2019-12-08 11:50:33

问题


I'm trying to create plugin which uses some functions from external dll-s. Because I don't know which plugin will be used I would like to dynamically load:

  1. main asp.net core project which dynamically loads plugins like mailservice.dll using reflection.

  2. mailservice.dll library which exposes CheckMail() method (I use MimeKit as a IMAP helper).

Everything loads fine but when I invoke CheckMail() method I receive System.IO.FileNotFoundException: Could not load file or assembly 'MailKit, Version=1.16.0.0. So I put all dependencies for MimeKit extracted from release version and still nothing (46 files). When I install MimeKit package using nuget to my main asp.net project everything runs fine but obviously I don't want keep such dependency.

Is there any tool or technique to inspect which file is missing?


回答1:


To get assembly probing path from the dotnet core host,you can enable core host tracing.
If you are running from Visual Studio, Go to command prompt and location of your asp.net core main solution

set the environment variable with this command first

set COREHOST_TRACE=1

After that just run using dotnet run and you will get full details

To redirect the output to the text file,use redrection

dotnet run 2> log.txt

note: You need the '2>' redirection as dotnet host writes to the STDERR stream and not STDOUT.Your regular logging will be STDOUT .Hope this helps



来源:https://stackoverflow.com/questions/43792974/inspect-dependencies-for-dynamically-loaded-library-in-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!