0

我收到此错误

System.IO.FileNotFoundException:'无法加载文件或程序集'CefSharp.Core,版本 = 63.0.3.0,文化 = 中性,PublicKeyToken = 40c4b6fc221f4138'。该系统找不到指定的文件。'

我正在尝试在.net core 2.0中运行cefsharp.minimalexample.offscreen程序。在视觉工作室 2017 中

到目前为止我做了什么

1. 创建 .net 核心控制台应用程序

2. 安装的 NuGet 包 Cefsharp.Offscreen(安装依赖项 cefsharp.common 和 redist)

3. 安装了 Microsoft.windows.compatibility nuget 包以在 .net 核心中获取 system.drawing(它不能与 System.Drawing.Common 一起使用 system.drawing 作为 Cefsharp ScreenshotAsync函数)

这些步骤将清除所有错误,项目将成功构建。

我收到上述错误。
我已经检查了当前运行文件夹(调试)中 Cefsharp 文档中提到的所有必需文件。所有文件都可用,但错误仍然没有消失。

它在旧的 Dot net 版本 4.6 中运行良好。

我在任何地方都找不到使用 .net core 实现 cefsharp.offscreen 的任何帮助文档。

这是 Cefsharp.offscreen 中提供的示例中的代码。

如果您能对这个问题有所了解,请告诉我。提前致谢。

public class Program
{
    private static ChromiumWebBrowser browser;

    public static void Main(string[] args)
    {
        const string testUrl = "https://www.google.com/";

        Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl);
        Console.WriteLine("You may see Chromium debugging output, please wait...");
        Console.WriteLine();

        var settings = new CefSettings()
        {
            //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
            CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
        };

        //Perform dependency check to make sure all relevant resources are in our output directory.
        Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

        // Create the offscreen Chromium browser.
        browser = new ChromiumWebBrowser(testUrl);

        // An event that is fired when the first page is finished loading.
        // This returns to us from another thread.
        browser.LoadingStateChanged += BrowserLoadingStateChanged;

        // We have to wait for something, otherwise the process will exit too soon.
        Console.ReadKey();

        // Clean up Chromium objects.  You need to call this in your application otherwise
        // you will get a crash when closing.
        Cef.Shutdown();
    }

    private static void BrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
    {
        // Check to see if loading is complete - this event is called twice, one when loading starts
        // second time when it's finished
        // (rather than an iframe within the main frame).
        if (!e.IsLoading)
        {
            // Remove the load event handler, because we only want one snapshot of the initial page.
            browser.LoadingStateChanged -= BrowserLoadingStateChanged;

            var scriptTask = browser.EvaluateScriptAsync("document.getElementById('lst-ib').value = 'CefSharp Was Here!'");

            scriptTask.ContinueWith(t =>
            {
                //Give the browser a little time to render
                Thread.Sleep(500);
                // Wait for the screenshot to be taken.
                var task = browser.ScreenshotAsync();
                task.ContinueWith(x =>
                {
                    // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png)
                    var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png");

                    Console.WriteLine();
                    Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath);

                    // Save the Bitmap to the path.
                    // The image type is auto-detected via the ".png" extension.
                    task.Result.Save(screenshotPath);

                    // We no longer need the Bitmap.
                    // Dispose it to avoid keeping the memory alive.  Especially important in 32-bit applications.
                    task.Result.Dispose();

                    Console.WriteLine("Screenshot saved.  Launching your default image viewer...");

                    // Tell Windows to launch the saved image.
                    Process.Start(screenshotPath);

                    Console.WriteLine("Image viewer launched.  Press any key to exit.");
                }, TaskScheduler.Default);
            });
        }
    }
}
4

0 回答 0