[英]Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified
[英]Could not load file or assembly "path" or one of its dependencies. The system cannot find the file specified
我有一個服務。 我嘗試使用 c# 安裝它。 即使存在服務文件,我也收到錯誤消息Could not load file or assembly 'file:///C:\\Sample\\sample.exe' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'file:///C:\\Sample\\sample.exe' or one of its dependencies. The system cannot find the file specified.
我使用 installutil 進行安裝,它成功了。
string Path = @"C:\sample\sample.exe";
string[] commandLineOptions = new string[1] { "/LogFile=install.log" };
using (AssemblyInstaller installer = new AssemblyInstaller(Path, commandLineOptions))
{
installer.UseNewContext = true;
installer.Install(null);
installer.Commit(null);
}
此代碼產生錯誤與 installutil 成功相同的路徑。 我檢查了路徑,sample.exe 文件存在於指定位置。 為什么會出現這個錯誤?
編輯
第一次運行時,此代碼文件不存在,並且會發生異常。 那時我會將文件復制到指定位置並再次調用相同的代碼。 第二次實際文件存在但顯示相同的錯誤消息。
使用AssemblyInstaller
我們需要卸載文件。
var domain = AppDomain.CreateDomain("MyDomain");
using (AssemblyInstaller installer = domain.CreateInstance(typeof(AssemblyInstaller).Assembly.FullName, typeof(AssemblyInstaller).FullName, false, BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.ExactBinding, null, new Object[] { Path, new String[] { } }, null, null, null).Unwrap() as AssemblyInstaller)
{
installer.UseNewContext = true;
installer.Install(null);
installer.Commit(null);
}
AppDomain.Unload(domain);
使用AppDomain
我們可以卸載程序集。 通過這個 .exe 文件將在操作后被釋放
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.