gpt4 book ai didi

.net - 无法加载文件或程序集

转载 作者:行者123 更新时间:2023-12-03 18:20:58 25 4
gpt4 key购买 nike

这是我的错误消息:

Could not load file or assembly 'file:///C:\Windows\system32\Rule.dll'. The system cannot find the file specified.



问题是同一个 exe 可以在我的开发环境中运行,但不能在生产服务器上运行。该程序是一种应作为 Windows Server 2008 上的计划任务运行的工具。它包含一个 exe,即所谓的 Database.dll 和 Rule.dll。该 exe 应在代码隐藏中动态加载 Rule.dll,但仅在从任务计划程序启动时才会失败并出现上述错误。为什么它在 System32 文件夹中而不是在 Application 文件夹中查找?这是UAC的问题吗?
'Load the rule engine into memory
Dim asmRule As System.Reflection.Assembly = Nothing
Try
asmRule = System.Reflection.Assembly.LoadFrom("Rule.dll") 'fails on productive system
Catch ex As System.Exception
HistoryLog.writeLog("SysLog", ex, "Cannot find Rule.dll in Application Folder")
End Try

最佳答案

方法LoadFrom将使用 Environment.CurrentDirectory构建将加载的程序集的完整路径。当前目录与应用程序基本路径不同。

您应该提供到 LoadFrom 的完整路径方法,您可以使用 AppDomain.CurrentDomain.BaseDirectory 构建它如果文件位于同一文件夹中,则可执行文件。

关于.net - 无法加载文件或程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3187088/

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