c# - 使用 AppDomain 加载程序集时出现 FileNotFoundException
问题描述
我想加载和卸载在当前应用程序域之外找到的程序集。阅读以下主题后,
- AppDomain.Load() 失败并出现 FileNotFoundException
- 卸载装有 Assembly.LoadFrom() 的程序集<-我无法理解该线程的答案
- 在不同的 AppDomain 中加载/卸载程序集<- 我将目标程序集文件夹位置放在私有 bin 路径中,导致
FileNotFoundException
我有以下代码引发FileNotFoundException
.
// let's assume that the executable running this code is found at "F:\\Test.exe"
// this is the assembly I want to load
string pathToAssembly = "C:\\Documents\\hello.dll";
// copied directly from the 1st link
AppDomain dom = AppDomain.CreateDomain("some");
AssemblyName assemblyName = new AssemblyName();
assemblyName.CodeBase = pathToAssembly;
Assembly assembly = dom.Load(assemblyName); // raises FileNotFoundException
我检查了文档: https ://docs.microsoft.com/en-us/dotnet/framework/app-domains/how-to-load-assemblies-into-an-application-domain https://docs.microsoft。 com/en-us/dotnet/framework/app-domains/how-to-unload-an-application-domain
但它没有使用 AppDomain从绝对路径加载和卸载。
基于第二个链接,AppDomains 在其当前可执行文件的目录路径中搜索程序集。当然,我需要解决这个问题,因为我需要在当前目录之外加载一个托管库。
而且,有关其他信息,我正在使用 .NET 框架 4.7.2 使用 WPF
TLDR:我需要更改 AppDomain 的“外观”目录吗?或者我能做些什么来解决这个问题?
解决方案
推荐阅读
- python - 写入行数超过 45 字节的二进制文件:binascii.Error: 一次最多 45 字节
- database - Azure Cosmos DB 分区键
- c# - 如何使用问号使用 lambda/LINQ 进行通配符 DataTable 选择?
- c++ - 在 C++ 中检测不安全的 const 引用绑定
- html - Angular 7,Asp.net web api,为用户分配角色
- firebase - 在单元测试类中使用 FirebaseAuth 时出错
- ruby - 如何删除以“a”开头直到下一个“b”的子字符串?
- r - R中有没有办法直观地显示哪个属性导致层次聚类中的聚类?
- javascript - 使用方形后退设置嵌套对象的值返回未定义
- javascript - JS Require 语句未定义变量