![](/img/trans.png)
[英]Could not load file or assembly 'Microsoft.Bot.Builder, Version=3.4.0.0, The system cannot find the file specified.",
[英]Trying to load an app through reflection and get error “Could not load file or assembly…The system cannot find the file specified.”
它要查找的程序集不是根程序集-它是被引用的程序集,但是在同一文件夹中,而Directory.GetCurrentDirectory()是其中包含所有文件的文件夹。
我被卡住了-有什么建议吗?
您可以:
AppDomain
来加载程序集(并将AppDomain
的基本目录设置为包含所有程序集的目录)。 AppDomain.AssemblyResolve
附加一个处理程序,以帮助CLR查找程序集的依赖项。 你可以尝试使用这样的东西
string myDll = string.Empty;
string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
myDll = string.Format(@"{0}\my.assembly.name.dll", location.Substring(0, location.LastIndexOf(@"\")));
}
这应该获得运行程序集的物理目录。 这可能在Windows .NET临时目录中。 但是,由于文件处于同一级别,因此它们应该并排存在。
如果使用assembly.loadfrom ,则可以指定程序集的文件路径。
从源加载上下文允许从探测中未包括的路径加载程序集,但是由于该路径信息由上下文维护,因此允许查找并加载对该路径的依赖性。
从具有引用的dll的文件夹中执行程序也可以解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.