0
現在、CefSharp RegisterJsObjectを使用しているときに問題が発生していました。私のコードは以下の通りです。CefSharp RegisterJsObject throw StackOverflowException
私は<package id="cef.redist.x64" version="3.2704.1432" targetFramework="net45" />
<package id="cef.redist.x86" version="3.2704.1432" targetFramework="net45" />
<package id="CefSharp.Common" version="51.0.0-pre02" targetFramework="net45" />
<package id="CefSharp.WinForms" version="51.0.0-pre02" targetFramework="net45" />
Program.csの私はラインRegisterJsObjectには、内部例外の詳細をAn unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
を得ることに保つ
namespace Project1
{
public static class Program
{
[STAThread]
private static void Main()
{
Initialize();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var cefSettings = new CefSettings
{
UserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36"
};
Cef.Initialize(cefSettings);
new FormSplash().Show();
Application.Run();
}
}
}
FormSplash.cs
namespace Project1
{
public partial class FormSplash : Form
{
public ChromiumWebBrowser Browser { get; set; }
public JsObject JsObj { get; set; }
public FormSplash()
{
InitializeComponent();
JsObj = new JsObject(this);
}
private void FormChromeToneExcelRegistration_Load(object sender, EventArgs e)
{
Browser = new ChromiumWebBrowser("https://google.com");
Browser.RegisterJsObject("jsObj", new JsObject(this));
Browser.FrameLoadStart += Browser_FrameLoadStart;
Browser.FrameLoadEnd += Browser_FrameLoadEnd;
Controls.Add(Browser);
Browser.Dock = DockStyle.Fill;
}
private void SetMessage(string message)
{
...
}
public class JsObject
{
public FormSplash Form { get; set; }
public JsObject(FormSplash form)
{
Form = form;
}
public void SetMessage(string message)
{
Form.SetMessage(message);
}
}
}
}
を使用しています
。
シナリオ私も試してみた:
- 変更SetMessage setMessage(動作しない)に
- が入れ子になったクラスを移動(動作しない)
私は」以下のコードとその作業を試しました。
Browser.RegisterJsObject("jsObj", "");
Browser.RegisterJsObject("jsObj", new {});
Browser.RegisterJsObject("jsObj", new DateTime());
なぜ私のプロジェクトでは、StackOverflowExceptionをスローするクラスを助けてくださいできますか?
にするか、プロパティに 'JavascriptIgnoreAttribute'属性を追加してください。ありがとうございました@emitland。 – amaitland
それは今の仕事です! –