gpt4 book ai didi

c# - 设置环境变量以在运行时使用 C# 查找 dll

转载 作者:行者123 更新时间:2023-11-30 22:34:34 25 4
gpt4 key购买 nike

我使用 ANTLR 来解析文档,我需要一些 ANTLR dll。对于编译,我可以使用/lib: 来定位 ANTLR dll 库所在的位置,但是当我运行执行二进制文件时,我收到了错误消息。

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Antlr3.Runtime, Version=3.1.3.421
54, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7' or one of its dependencies. The system cannot find the file specif
ied.
at Antlr.Examples.LLStar.LLStarApp.Main(String[] args)

当我将 ANTLR dll 复制到执行二进制文件所在的同一目录时,错误消失了。

我在路径中添加了dll所在的目录,还是不行。如何设置环境变量或其他东西来查找 dll?我使用 Windows 7。

已添加

我想没有办法使用 PATH 或环境变量来做到这一点,我认为 GAC 是一种解决方案,Set Custom Path to Referenced DLL's?是另一种解决方案,即使它只能找到执行二进制文件所在目录下的子目录。

最佳答案

AppDomain.CurrentDomain.SetupInformation.PrivateBinPathProbe

AppDomain.CurrentDomain.AssemblyResolve += (sndr,resolveEventArgs) =>
{
if(resolveEventArgs.Name==something){
return Assembly.LoadFile(assemblyPath);
}
return null;
};

关于c# - 设置环境变量以在运行时使用 C# 查找 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7759628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com