简体   繁体   中英

C# Winform with CefSharp app crash on publish version

I create an C# Winform application with CefSharp Project. The application works great in the debug mode but when i try to publish it with VS2013 it's crash before the application start to run.

This is my program.cs file:

    [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;
    }

When i checked the publish folder i only see this files: 在此处输入图片说明

And from the CefSharp Wiki i understand that there are couple of files that missing. Any idea what can be the problem?

I run and publish the project with Visual Studio 2013 . I'm using Any CPU for the compile.

EDIT

<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>

I added this and now the application crash with this error:

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.

Any CPU is the issue.

You can select either x64 or x86 platform.

  1. Make sure you have added reference to CefSharp.Winforms nuget

  2. Make sure that the platform of solution is set to x86 / x64 explicitly instead of Any CPU.

  3. Add below runtime binding in the configuration file:

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

  4. CSProj file should have below property set:

    <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>

Refer this article - which explains step by step process of setting up CEFSharp browser in winforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM