Tim*_*ter 4 .net vb.net dll scheduled-tasks
这是我的错误消息:
无法加载文件或程序集'file:/// C:\ Windows\system32\Rule.dll'.该系统找不到指定的文件.
问题是同一个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
Run Code Online (Sandbox Code Playgroud)
The method LoadFrom will use Environment.CurrentDirectory to build the full path to the assembly that will be loaded. The current directory is not the same as the application base path.
You should provide the full path to LoadFrom method, you can build it using AppDomain.CurrentDomain.BaseDirectory if the file is located in the same folder then the executable.
Have you tried:
asmRule = Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Rule.dll"));
Run Code Online (Sandbox Code Playgroud)