C# CefSharp wpf 找不到依赖项

C# CefSharp wpf cant locate dependecies

我有一个简单的 wpf 应用程序,它使用 CefSharp 和初始化设置缓存路径:

try
{
    var settings = new CefSettings();
    settings.CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Cache");
    Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
}
catch (Exception e)
{
    MessageBox.Show(e.ToString());
}

它运行良好,但我在系统启动时使用此代码启动:

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().Location);

如果应用程序在启动时由系统启动,我会在 catch 块中收到此错误:

System.Exception: Unable to lacte requred Cef/CefSharp dependencies:
Missing:CefSharp.BrowserSubprocess.exe
Missing:CefSharp.BrowserSubProcess.Core.dll
Missing:CefSharp.Core.dll
Missing:icudtl.dat
Missing:libcef.dll

但是当我 运行 手动应用程序时它运行良好。 谢谢!

因为working directory不是你应用的bin目录

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().Location);

有很多方法可以将当前目录更改为应用程序的 bin 路径。最简单的方法是更改​​代码中的当前目录(如您所建议的那样)。

Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain‌​.BaseDirectory);