【问题标题】:C# Winform with CefSharp app crash on publish versionC# Winform 与 CefSharp 应用程序在发布版本上崩溃
【发布时间】:2019-01-20 15:15:28
【问题描述】:

我使用CefSharp 项目创建了一个C# Winform 应用程序。 该应用程序在调试模式下运行良好,但是当我尝试使用 VS2013 发布它时,它在应用程序开始运行之前就崩溃了。

这是我的 program.cs 文件:

    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.AssemblyResolve += Resolver;

        LoadApp();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void LoadApp()
    {
        var settings = new CefSettings();

        settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                               Environment.Is64BitProcess ? "x64" : "x86",
                                               "CefSharp.BrowserSubprocess.exe");

        settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TelegramParser\CEF";
        settings.IgnoreCertificateErrors = true;
        settings.WindowlessRenderingEnabled = true;
        settings.SetOffScreenRenderingBestPerformanceArgs();

        Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

        Application.Run(new Form1());
    }

    private static Assembly Resolver(object sender, ResolveEventArgs args)
    {
        if (args.Name.StartsWith("CefSharp"))
        {
            string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
            string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                                   Environment.Is64BitProcess ? "x64" : "x86",
                                                   assemblyName);

            return File.Exists(archSpecificPath)
                       ? Assembly.LoadFile(archSpecificPath)
                       : null;
        }

        return null;
    }

当我检查发布文件夹时,我只看到以下文件:

CefSharp Wiki 我了解到有几个文件丢失了。知道可能是什么问题吗?

我使用Visual Studio 2013 运行和发布项目。 我使用Any CPU 进行编译。

编辑

<ItemGroup>
<Content
Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
  <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  <Visible>false</Visible>
</Content>

  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-US.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x86\**\CefSharp.BrowserSubprocess.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Content
    Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-US.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x64\**\CefSharp.BrowserSubprocess.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

我添加了这个,现在应用程序崩溃并出现此错误:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in App.exe

Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.

【问题讨论】:

  • 缺少哪些文件?
  • 这应该作为副本关闭。
  • @amaitland 我看到了这个线程,但是当我在应用程序中包含 if .csproj 并尝试使用 VS2013 运行它并对其进行调试时,我收到此错误:Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found. 我正在使用任何 CPU 和完成了这个线程中提到的所有事情:https://github.com/cefsharp/CefSharp/issues/1714 - 选项 2。在我添加包含文件之前,调试工作很好。
  • 编辑您的原始帖子以详细包含您尝试过的内容。关于您尝试了某事但没有成功的含糊陈述不足以让我提供帮助。

标签: c# winforms chromium cefsharp


【解决方案1】:

任何 CPU 都是问题。

您可以选择 x64 或 x86 平台。

  1. 确保您已添加对 CefSharp.Winforms nuget 的引用

  2. 确保解决方案的平台明确设置为 x86 / x64 而不是 Any CPU。

  3. 在配置文件中添加下面的运行时绑定:

    <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="x86"/> </assemblyBinding> </runtime>

  4. CSProj 文件应具有以下属性集:

    &lt;CefSharpAnyCpuSupport&gt;true&lt;/CefSharpAnyCpuSupport&gt;

请参阅this article - 它解释了在 winforms 中设置 CEFSharp 浏览器的逐步过程。

【讨论】:

  • 但是 CefSharp 支持任何 Cpu。
  • Somhow anycpu 对我不起作用。我检查了文档,在 63.0.2 之后,似乎支持任何 cpu。您能否在问题中提及您使用的是哪个版本。您也可以尝试我的回答中提到的步骤 - 它们应该可以工作。
  • 是的...正在改变 x86 的东西是针对旧版本的...
猜你喜欢
  • 1970-01-01
  • 2017-03-15
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2013-04-30
相关资源
最近更新 更多