Publish Could not load file or assembly CefSharp.Core.dll

≡放荡痞女 提交于 2021-01-29 05:06:26

问题


I'm using CefSharp in my C# Windows form Application and it's working well when I run it from visual studio, but when I publish it using FTP account as publish folder and url as installation folder url

but I'm getting the following error,

I followed everything in the manual and copied the needed files into bin folder (CefSharp.BrowserSubprocess.Core.dll, CefSharp.BrowserSubprocess.exe, CefSharp.Core.dll, CefSharp.dll, CefSharp.WinForms.dll, icudtl.dat, libcef.dll)

unfortunately nothing works, where is the problem?

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
File name: 'CefSharp.Core.dll'
   at mibrsdmapp.webBrowserForm.InitializeChromium()
   at mibrsdmapp.webBrowserForm..ctor()
   at mibrsdmapp.MeetingManager.btnCreate_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4001.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
mibrsdmapp
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/mibrsdmapp.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4150.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.3752.0 built by: NET48REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.3752.0 built by: NET48REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Newtonsoft.Json
    Assembly Version: 12.0.0.0
    Win32 Version: 12.0.3.23909
    CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/Newtonsoft.Json.DLL
----------------------------------------
RestSharp
    Assembly Version: 106.11.4.0
    Win32 Version: 106.11.4
    CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/RestSharp.DLL
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.3752.0 built by: NET48REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Web
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4075.0 built by: NET48REL1LAST
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
System.Deployment
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.3752.0 built by: NET48REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Deployment/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
----------------------------------------
CefSharp.WinForms
    Assembly Version: 83.4.20.0
    Win32 Version: 83.4.20.0
    CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/CefSharp.WinForms.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

回答1:


I managed to collect all the needed files mentioned Here in one folder and name it dll then I put it in the packages folder

now in .csproj and before </Project> I added

  <ItemGroup>
    <Content Include="$(SolutionDir)packages\dll\**\*.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

the application wored after the publish and it's solved




回答2:


I'm a little late but to add on here I use the following as a solution to the problem of moving the CEFSharp files into a subfolder. (Credit to https://gist.github.com/BlackBooth/19ce027c4f68c1eb4fc1144988ca6662)

using CefSharp;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace TestApp
{
    internal static class Program
    {
        // The subfolder, where the cefsharp files will be moved to
        private static string cefSubFolder = "CEFSharp";
        // If the assembly resolver loads cefsharp from another folder, set this to true
        private static bool resolved = true;

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

            InitializeCefSharp();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void InitializeCefSharp()
        {
            var settings = new CefSettings();
            
            // Set BrowserSubProcessPath when cefsharp moved to the subfolder
            if (resolved)
                settings.BrowserSubprocessPath = Path.Combine(Application.StartupPath, cefSubFolder, "CefSharp.BrowserSubprocess.exe");

            // Make sure you set performDependencyCheck false
            Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: false);
        }

        /// <summary>
        /// Will attempt to load missing assemblys from subfolder
        /// </summary>
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (args.Name.StartsWith("CefSharp"))
            {
                resolved = true; // Set to true, so BrowserSubprocessPath will be set

                string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
                string subfolderPath = Path.Combine(Application.StartupPath, cefSubFolder, assemblyName);
                return File.Exists(subfolderPath) ? Assembly.LoadFile(subfolderPath) : null;
            }

            return null;
        }
    }
}

And then in Visual Studio I use the following build events.

Pre-build:

RD /S /Q "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"

Post-Build:

dir /b /a-d "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\"|findstr /b "$(TargetName)" >"%temp%\searchfiles.tmp"

mkdir CEFSharp

xcopy "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp" /exclude:%temp%\searchfiles.tmp /y

cd  "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\"

attrib +r $(TargetName).*
del /q *
attrib -r $(TargetName).*

move "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\locales" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"

move "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\swiftshader" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"

Even better, as @amaitland suggested modify your project to include CefSharpTargetDir before the CefSharp targets and the files will be copied to a subfolder as part of the build. See: https://github.com/cefsharp/CefSharp/blob/cefsharp/83/NuGet/CefSharp.Common.targets#L12

 <PropertyGroup>
    <CefSharpTargetDir Condition=" '$(CefSharpTargetDir)' == '' ">CEFSharp</CefSharpTargetDir>
  </PropertyGroup>


来源:https://stackoverflow.com/questions/63124520/publish-could-not-load-file-or-assembly-cefsharp-core-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!