- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我创建了一个使用 ChromiumBrowser 的 Windows 窗体应用程序。该应用程序由以下组件组成:
当我正常启动我的应用程序时,网络浏览器工作正常。如果我从启动器启动我的应用程序,Web 浏览器将无法工作。它告诉我以下错误:
Unhandled exception of 'System.IO.FileNotFoundException' in Unknown module.
Cannot load file or assembly 'CefSharp, Version=57.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or a relative dependency.
Unable to found the specified file.
我不仅需要使用启动器进行更新,而且由于应用程序分布在网络上,有时访问服务器上的文件会出现问题。
问题不仅与我的应用有关。我创建了一个测试解决方案并在下面发布,但我遇到了同样的问题。
Cefsharp 版本 57(Cef redist 3.2987.1601)
x64 文件夹
x86文件夹
我发布了给出相同错误的测试解决方案。
测试方案由三个项目组成:
代码如下:
程序.cs
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace StackOverflowIssueLauncher {
/// <summary>
/// Launcher program
/// </summary>
internal static class Program {
/// <summary>
/// Launcher body
/// </summary>
[STAThread, LoaderOptimization(LoaderOptimization.MultiDomainHost)]
private static void Main() {
//Initialize path of application
string startupPath = Environment.CurrentDirectory;
string cachePath = Path.Combine(Path.GetTempPath(), "Program-" + Guid.NewGuid());
string assemblyPath = CanonicalizePathCombine(startupPath, @"..\..\..\StackOverflowIssue\bin\Debug\");
string executablePath = Path.Combine(assemblyPath, "StackOverflowIssue.exe");
string configFile = executablePath + ".config";
//Start App Domain
try {
var setup = new AppDomainSetup() {
ApplicationName = "StackOverflowIssue",
ShadowCopyFiles = "true",
ShadowCopyDirectories = assemblyPath,
CachePath = cachePath,
ConfigurationFile = configFile
};
var domain = AppDomain.CreateDomain("StackOverflowIssue", AppDomain.CurrentDomain.Evidence, setup);
domain.ExecuteAssembly(executablePath);
AppDomain.Unload(domain);
}
catch (Exception ex) {
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Empty cache path
try {
Directory.Delete(cachePath, true);
}
catch (Exception) {
//DO NOTHING
}
}
private static string CanonicalizePathCombine(string sourcePath, string destPath) {
string resultPath = Path.Combine(sourcePath, destPath);
var sb = new StringBuilder(Math.Max(260, 2 * resultPath.Length));
PathCanonicalize(sb, resultPath);
return sb.ToString();
}
[DllImport("shlwapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool PathCanonicalize([Out] StringBuilder sb, string src);
}
}
WebControlForm.cs
using System.Windows.Forms;
using WebBrowser;
namespace StackOverflowIssue {
/// <summary>
/// Form that contains the webbrowser control
/// </summary>
public class WebControlForm : Form {
/// <summary>
/// Create a new web control form
/// </summary>
public WebControlForm() {
InitializeComponent();
Controls.Add(new CefControl { Dock = DockStyle.Fill });
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.SuspendLayout();
//
// WebControlForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(529, 261);
this.Name = "WebControlForm";
this.Text = "WebControlForm";
this.ResumeLayout(false);
}
#endregion
}
}
主窗体.cs
using System;
using System.Windows.Forms;
namespace StackOverflowIssue {
/// <summary>
/// Main application form
/// </summary>
public partial class MainForm : Form {
/// <summary>
/// Creates the main form
/// </summary>
public MainForm() {
InitializeComponent();
}
/// <summary>
/// Show a new Web Control form
/// </summary>
/// <param name="sender">Object that raised the event</param>
/// <param name="e">Event arguments</param>
private void ShowBtn_Click(object sender, EventArgs e) {
var wcf = new WebControlForm();
wcf.Show(this);
}
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione Windows Form
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent() {
this.ShowBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ShowBtn
//
this.ShowBtn.Location = new System.Drawing.Point(12, 12);
this.ShowBtn.Name = "ShowBtn";
this.ShowBtn.Size = new System.Drawing.Size(134, 40);
this.ShowBtn.TabIndex = 0;
this.ShowBtn.Text = "Show web browser";
this.ShowBtn.UseVisualStyleBackColor = true;
this.ShowBtn.Click += new System.EventHandler(this.ShowBtn_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.ShowBtn);
this.Name = "MainForm";
this.Text = "Main form";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button ShowBtn;
}
}
程序.cs
using System;
using System.Diagnostics;
using System.Windows.Forms;
using WebBrowser;
namespace StackOverflowIssue {
/// <summary>
/// Main application program
/// </summary>
internal static class Program {
/// <summary>
/// Main application program.
/// </summary>
[STAThread] private static void Main() {
WebBrowserInitializer.Initialize();
Debug.Print("Application started");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="cef.redist.x64" version="3.2987.1601" targetFramework="net452" />
<package id="cef.redist.x86" version="3.2987.1601" targetFramework="net452" />
<package id="CefSharp.Common" version="57.0.0" targetFramework="net452" />
<package id="CefSharp.WinForms" version="57.0.0" targetFramework="net452" />
</packages>
CefControl.cs
using System.Windows.Forms;
using CefSharp.WinForms;
namespace WebBrowser {
/// <summary>
/// WebBrowser control
/// </summary>
public class CefControl: UserControl {
public CefControl() {
CefInitializer.Initialize();
InitializeComponent();
var cr = new ChromiumWebBrowser("https://www.google.com");
cr.Dock = DockStyle.Fill;
Controls.Add(cr);
}
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione componenti
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
CefInitializer.cs
using CefSharp;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace WebBrowser {
/// <summary>
/// Class that contains the base methods for CEF initializations
/// </summary>
public static class CefInitializer {
/// <summary>
/// Initialize properties
/// </summary>
static CefInitializer() {
CachePath = Path.Combine(Path.GetTempPath(), "SOIssue", "Cache");
LogFile = Path.Combine(Path.GetTempPath(), "SOIssue", "Logs");
UserDataPath = Path.Combine(Path.GetTempPath(), "SOIssue", "Data");
if (!Directory.Exists(CachePath))
Directory.CreateDirectory(CachePath);
if (!Directory.Exists(LogFile))
Directory.CreateDirectory(LogFile);
if (!Directory.Exists(UserDataPath))
Directory.CreateDirectory(UserDataPath);
//Complete the files combine
LogFile = Path.Combine(LogFile, "WebBrowser.log");
AppDomain.CurrentDomain.DomainUnload += (sender, args) => Shutdown();
}
/// <summary>
/// Shutdown all CEF instances
/// </summary>
internal static void Shutdown() {
using (var syncObj = new WindowsFormsSynchronizationContext()) {
syncObj.Send(o => {
if (Cef.IsInitialized)
Cef.Shutdown();
}, new object());
}
}
/// <summary>
/// Initialize CEF libraries
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)] internal static void Initialize() {
if (Cef.IsInitialized)
return;
//Get proxy properties
WebProxy proxy = WebRequest.DefaultWebProxy as WebProxy;
string cefPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Cef)).Location);
Debug.Print($"CEF Library Path: {cefPath}");
Debug.Assert(cefPath != null, nameof(cefPath) + " != null");
var settings = new CefSettings() {
BrowserSubprocessPath = Path.Combine(cefPath, "CefSharp.BrowserSubprocess.exe"),
LocalesDirPath = Path.Combine(cefPath, "locales"),
ResourcesDirPath = cefPath,
Locale = CultureInfo.CurrentCulture.Name,
CachePath = CachePath,
LogFile = LogFile,
UserDataPath = UserDataPath
};
if (proxy == null || proxy.Address.AbsoluteUri != string.Empty)
settings.CefCommandLineArgs.Add("no-proxy-server", string.Empty);
Cef.Initialize(settings);
}
internal static readonly string CachePath;
internal static readonly string LogFile;
internal static readonly string UserDataPath;
}
}
WebBrowserInitializer.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace WebBrowser {
/// <summary>
/// Class that contains the assembly resolve functions
/// </summary>
public static class WebBrowserInitializer {
private static readonly object _initializer = new object();
private static bool _initialized;
/// <summary>
/// Check if the WebBrowser is initialized
/// </summary>
public static bool IsInitialized {
get {
lock (_initializer)
return _initialized;
}
}
/// <summary>
/// Initialize the current assembly
/// </summary>
public static void Initialize() {
lock (_initializer) {
if (!_initialized) {
AppDomain.CurrentDomain.AssemblyResolve += CefSharp_AssemblyResolve;
_initialized = true;
}
}
}
/// <summary>
/// Try to resolve the assembly
/// </summary>
/// <param name="sender">Object that has raised the event</param>
/// <param name="args">Event raised</param>
/// <returns>Assembly loaded</returns>
private static Assembly CefSharp_AssemblyResolve(object sender, ResolveEventArgs args) {
Debug.Print($"Library: {args.Name}");
if (!args.Name.StartsWith("CefSharp", StringComparison.OrdinalIgnoreCase))
return null;
string assemblyName = args.Name.Split(new[] {','}, 2)[0] + ".dll";
foreach (var path in GetAssemblyPaths()) {
string checkPath = Path.Combine(path, assemblyName);
if (File.Exists(checkPath)) {
Debug.Print($"Relative path FOUND for {args.Name} in {checkPath}");
return Assembly.UnsafeLoadFrom(checkPath);
}
Debug.Write($"Relative path not found for {args.Name} in {checkPath}");
}
return null;
}
/// <summary>
/// Get all possible assembly paths
/// </summary>
/// <returns>List of possible assembly paths</returns>
private static IEnumerable<string> GetAssemblyPaths() {
string pathPrefix = Environment.Is64BitProcess ? "x64" : "x86";
if (Directory.Exists(@"C:\Program Files (x86)\CEFRuntime\" + pathPrefix))
yield return @"C:\Program Files (x86)\CEFRuntime\" + pathPrefix;
yield return Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, pathPrefix);
yield return Path.Combine(Environment.CurrentDirectory, pathPrefix);
Assembly currentAssembly = Assembly.GetAssembly(typeof(CefInitializer));
if (!string.IsNullOrEmpty(currentAssembly.Location))
yield return Path.Combine(currentAssembly.Location, pathPrefix);
}
}
}
packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="cef.redist.x64" version="3.2987.1601" targetFramework="net452" />
<package id="cef.redist.x86" version="3.2987.1601" targetFramework="net452" />
<package id="CefSharp.Common" version="57.0.0" targetFramework="net452" />
<package id="CefSharp.WinForms" version="57.0.0" targetFramework="net452" />
</packages>
最佳答案
查看 CefSharp 一般用法 (https://github.com/cefsharp/CefSharp/wiki/General-Usage#need-to-knowlimitation),我注意到一行解释 CefSharp 仅在默认 AppDomain 上工作。我看过项目https://github.com/stever/AppHostCefSharp我找到了解决方案。
我需要在默认 AppDomain 上运行 WebBrowser(我 fork 并编辑了 RedGate.AppHost 存储库。请参阅下文了解我这样做的原因。)。为了允许控件之间的通信,我实现了两个 NamedPipes 服务,一个在主窗体上,另一个在创建的对象上。
我发布了完整的解决方案 ( https://github.com/rupertsciamenna89/cefsharp-remoting ),因此源代码将更易于查看。它可以改进或修复(就像我的英语 :))
我将原始项目重命名为更好的名称。
该解决方案由 4 个项目组成:
此项目包含客户端和服务器必须实现的接口(interface)。它包含五个文件:
此项目实现初始化 Control WCF 服务的 OutOfProcessEntryPoint 接口(interface)。它包含服务器接口(interface)的实现,并允许远程客户端显示文件夹并检索返回的结果。
我编辑了接受二进制文件路径的 Program.Main。我将这个参数保存到一个静态变量中,我将使用它来创建子进程句柄。创建进程句柄的函数是这样的:
public static IChildProcessHandle CreateChildProcessHandle() {
string assemblyPath = _sourcePath ?? Path.GetDirectoryName(Assembly.GetAssembly(typeof(WebBrowserInitializer)).Location);
Debug.Assert(assemblyPath != null, "assemblyPath != null");
var al = new ChildProcessFactory() { ClientExecutablePath = _sourcePath };
return al.Create(Path.Combine(assemblyPath, "MainApplication.WebBrowser.dll"), false, Environment.Is64BitProcess);
}
如果没有传递源路径(比如我直接执行应用程序),RedGate 将使用默认位置(执行程序集路径)。
打开窗口后,用户可以按 Show(或 ShowDialog)按钮。应用程序“简单地”运行这些代码行:
//Generates client id and server id
string appId = Guid.NewGuid().ToString("N");
string controlId = Guid.NewGuid().ToString("N");
_service = AppServer.Start(appId, controlId);
_service.FormCompleted += Service_FormCompleted;
_locator = new FormServiceLocator(appId, controlId);
_element = _handle.CreateElement(_locator);
_service.StartRemoteClient();
_service.ShowDialog((long)Handle);
当用户将关闭窗口时,将调用回调函数:
private void Service_FormCompleted(object sender, AppServerEventArgs e) {
//Check if invoke is required
if (InvokeRequired) {
Invoke(new Action<object, AppServerEventArgs>(Service_FormCompleted), sender, e);
return;
}
_element = null;
MessageBox.Show(this, $"Result: {e.Result} - Data: {e.AdditionalData}");
}
这是在启用 ShadowCopy 的情况下启动我们的应用程序的项目。我将二进制文件的路径作为参数传递。
var domain = AppDomain.CreateDomain("CefSharp-Remoting",
AppDomain.CurrentDomain.Evidence, setup);
domain.ExecuteAssembly(executablePath, new[] { $"\"/path:{assemblyPath}\"" });
RedGate.AppHost 尝试找到查看程序集位置的客户端应用程序。启用 ShadowCopy 后,这是不可能的,因为应用程序被复制到“随机”文件夹中,并且客户端应用程序位于源路径中。
我将 ClientExecutablePath 属性添加到 ChildProcessFactory.cs 和 ProcessStarter.cs 中,因此如果设置了此属性,ProcessStarter 将使用此文件夹而不是默认文件夹。
您可以在以下文件中看到编辑:
关于c# - 使用 Shadow Copy 启动的 CefSharp 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47414728/
我无法创建另一个父 div 容器,是否可能仅使用 css 技巧?盒子阴影:7px 7px 7px 黑色;只会从右边框和底边框创建阴影,但我也需要左边框和上边框。 最佳答案 盒子阴影有4个参数;偏移量、
我刚遇到一个有趣的情况,我有一个提交 放置在 内的 native 自定义元素的 Shadow DOM 内. Select #shadow-root ...
假设我们有一些 CSS 代码,例如动画 CSS 加载器,我们希望在所有使用 Shadow DOM 的 Web 组件中使用它。如果我们无法像 ::shadow 那样穿透 Shadow DOM,我们如何重
shadow-dom 中的document 变量的值是多少?在 this jsfiddle 我们可以看到它在父文档中搜索 app 节点并提醒它的值。这是否意味着 shadow-dom 没有单独的文档变
以下代码是来自 chrome 开发工具的 View #shadow-root (user-agent) This I want to restyle 如果我想在 shadow
运行mvn package:shade shade时,日志中的条目显示:用 XYZ-shaded.jar 替换 XYZ.jar但在我的目标目录中,我找不到阴影 jar 这是我关于 Maven 阴影的
我正在尝试编写一个 mixin,它应该将 CSS box-shadow 作为参数并将其转换为 filter: drop-shadow()。 // mixin drop-shadow($shadows)
我正在使用 gradle shadow 插件构建我的 uber jar。 build.grade 文件看起来像: buildscript { repositories { jc
我正在尝试向子对象所在的父对象添加阴影 元素位于其中。我希望插入的阴影与图像重叠。 我的 HTML 代码是: 和 CSS: .highlights { height: 360px
我想在 UIView 上添加drop shadow 和stroke shadow这是我的设计师给我的阴影, 对于投影,他告诉我使用 RGB(176,199,226),不透明度为 90%,距离为 3,大
我希望在单击图像时出现投影。我目前不使用 Jquery,所以如果可能的话,请提供一个 java 脚本解决方案。这是我的 fiddle :http://jsfiddle.net/zUNhD/7/ 我还希
从那以后我一直在使用 CSS box-shadows,但现在我有一个带有圆 Angular 的图像并想给它一个圆 Angular 阴影。所以我尝试使用 filter: drop-shadow,但不幸的
LWC 合成影子 dom 似乎不像 native 影子 dom 实现那样处理插槽,例如 假设您从一个元素开始: Hi there 然后附加影子dom并添加一个插槽,h1将被插入: 现在,如果您在运行“
我试图在以下文档中观察文档级别的自定义输入元素的文本输入元素的输入值的变化: 其中自定义 Div 和自定义输入定义如下: Units 如状态h
我的网站上安装了一个 Angular 网络组件。它使用 Shadow DOM,因此它非常快(在我的情况下必须如此)。 在我的站点上,我还有一个快捷方式 h,它会打开一个显示一些有用信息的弹出窗口。 h
我正在尝试为一个带有与其文本颜色相同的阴影的框创建样式。因为我有几个框,每个框都有不同的文本颜色,所以我想避免在每个框的每个单独规则集中重复相同的颜色。 现在,背景和边框模块状态为 box-shado
我想使用不支持 Shadow-DOM 的浏览器(如 Firefox、PhantomJS 以及其他使用 WebDriver 的浏览器)测试 Polymer 应用程序。 当我使用类似的东西时,Firefo
我有一个 Assets 代表一个按钮,下面有一个阴影。我只想让蓝色部分可点击。有没有简单的方法来做到这一点? 谢谢。 最佳答案 您可以像这样以编程方式添加阴影: button.layer.shadow
我正在尝试创建一个 Photoshop 内阴影效果,与 css3 框阴影插入效果相同。 第 1 步(我正在生成按钮 - 圆 Angular 矩形): convert -size 220x50 xc:n
我需要在 boxMesh 上转换阴影,而网格本身应该不可见。 我找到了 technique Three.js GitHub 问题跟踪器似乎在几年前就可以工作,但现在不再工作了 - 它涉及创建一个新的着
我是一名优秀的程序员,十分优秀!