0

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: enter image description here

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.
YosiFZ
  • 7,792
  • 21
  • 114
  • 221
  • which files are missing? – Mario Mitterbauer Jan 20 '19 at 16:19
  • See https://stackoverflow.com/questions/34225222/clickonceinstall-cefsharp-winforms-problems and https://github.com/cefsharp/CefSharp/issues/1314 – amaitland Jan 20 '19 at 20:16
  • This should probably be closed as a duplicate. – amaitland Jan 20 '19 at 20:16
  • @amaitland I saw this threads but when i include if in the app `.csproj ` and try to run it with VS2013 and debug it i get this error: `Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.` I'm Using Any CPU and done everything like mention in this thread: `https://github.com/cefsharp/CefSharp/issues/1714` - Option 2. Before i add the include files the debug work great. – YosiFZ Jan 21 '19 at 08:02
  • Edit your original post to include what you tried, in detail. A vague statement about you tried something and it didn't work isn't enough for me to help. – amaitland Jan 21 '19 at 08:07
  • https://github.com/cefsharp/CefSharp/issues/1314#issuecomment-425607782 – amaitland Jan 21 '19 at 08:08
  • @amaitland i just edit my question, i also try to add your suggested code and it fail with the same error – YosiFZ Jan 21 '19 at 08:17
  • You can use http://msbuildlog.com/ to debug the `msbuild` output – amaitland Jan 21 '19 at 08:48

1 Answers1

1

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.

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37
  • But CefSharp Supports Any Cpu. – YosiFZ Jan 20 '19 at 17:06
  • Somhow anycpu did not work for me. I checked documentation and after 63.0.2, any cpu seems to be supported. Can you mention which version are you using in the question. Also can you try steps mentioned in my answer - they should work. – Manoj Choudhari Jan 20 '19 at 17:19
  • 1
    yeah... that's changing x86 stuff is for the older version... – gumuruh May 13 '20 at 06:33