【问题标题】:Publish Could not load file or assembly CefSharp.Core.dll发布无法加载文件或程序集 CefSharp.Core.dll
【发布时间】:2020-07-27 22:28:17
【问题描述】:

我在我的 C# Windows 窗体应用程序中使用 CefSharp,当我从 Visual Studio 运行它时它运行良好,但是当我使用 FTP 帐户作为发布文件夹和 url 作为安装文件夹 url 发布它时

但我收到以下错误,

我按照手册中的所有内容将所需文件复制到 bin 文件夹中 (CefSharp.BrowserSubprocess.Core.dll、CefSharp.BrowserSubprocess.exe、CefSharp.Core.dll、CefSharp.dll、CefSharp.WinForms.dll、icudtl.dat、libcef.dll)

不幸的是,没有任何效果,问题出在哪里?

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.

【问题讨论】:

  • 还要确保您安装了 Visual C++ 2015 或更高版本。
  • 我刚试了但是没用,不知道错过了什么
  • 到底试过什么?请详细说明,如果没有详细信息,我无法为您提供帮助。
  • 非常感谢我按照下面的答案解决了,现在我遇到了应用程序大小的问题,它超过 141 MB,我该如何减小它?

标签: c# .net winforms cefsharp


【解决方案1】:

我设法将Here 提到的所有需要​​的文件收集到一个文件夹中,并将其命名为 dll,然后我将其放入 packages 文件夹中

现在在 .csproj 和 &lt;/Project&gt; 之前我添加了

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

发布后应用磨损并解决

【讨论】:

    【解决方案2】:

    我有点晚了,但在这里补充一下,我使用以下解决方案来解决将 CEFSharp 文件移动到子文件夹中的问题。 (感谢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;
            }
        }
    }
    

    然后在 Visual Studio 中我使用以下构建事件。

    预编译:

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

    后期构建:

    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"
    

    更好的是,@amaitland 建议修改您的项目以在 CefSharp 目标之前包含 CefSharpTargetDir,并且文件将作为构建的一部分复制到子文件夹中。见:https://github.com/cefsharp/CefSharp/blob/cefsharp/83/NuGet/CefSharp.Common.targets#L12

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-10
    • 2023-04-07
    • 1970-01-01
    • 2013-01-29
    • 2016-11-09
    • 2020-08-17
    相关资源
    最近更新 更多