我有一个基于websocket的文本编辑器,我为大学项目编写。在我的本地机器上正常工作,但部署到Azure时出现错误。Azure应用程序提供HRESULT E_FAIL已从调用COM组件返回
将html转换为rtf时出现问题,我使用了here和here的混合代码。这需要在一个单线程单元中使用Windows窗体组件,并且有点头疼,但它确实有效......直到我迁移到Azure。
调试在Visual Studio中,我得到了错误信息:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147467259
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Navigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
at System.Windows.Forms.WebBrowser.PerformNavigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
at System.Windows.Forms.WebBrowser.set_Url(Uri value)
at System.Windows.Forms.WebBrowser.set_DocumentStream(Stream value)
at System.Windows.Forms.WebBrowser.set_DocumentText(String value)
at RealTimeTextEditor.HtmlRtfConvertor.ConvertHtmltoRtf(Object obj) in C:\DissertationProjectGitRepo\RealTimeTextEditor\RealTimeTextEditor\HtmlRtfConvertor.cs:line 30
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
InnerException:
有问题的代码可以在这里找到,在线路发生异常 “tempBrowser.DocumentText = data.html;”
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Windows.Forms;
namespace RealTimeTextEditor
{
public class HtmlRtfConvertor
{
public void ThreadConvertor(string inputpath, string inputhtml)
{
var t = new Thread(ConvertHtmltoRtf);
var dataForConversion = new ConvertorData { path = inputpath, html = inputhtml };
t.SetApartmentState(ApartmentState.STA);
t.Start(dataForConversion);
t.Join();
}
public static void ConvertHtmltoRtf (object obj)
{
var data = obj as ConvertorData;
using (WebBrowser tempBrowser = new WebBrowser())
{
tempBrowser.CreateControl();
tempBrowser.DocumentText = data.html;
while (tempBrowser.DocumentText != data.html)
{
Application.DoEvents();
}
tempBrowser.Document.ExecCommand("SelectAll", false, null);
tempBrowser.Document.ExecCommand("Copy", false, null);
using (RichTextBox rtb = new RichTextBox())
{
rtb.Paste();
rtb.SaveFile(data.path);
}
}
}
public class ConvertorData
{
public string path { get; set; }
public string html { get; set; }
}
}
}
调用HTML转换器类控制器代码:
HtmlRtfConvertor convertor = new HtmlRtfConvertor();
convertor.ThreadConvertor(path, html);
你在哪里部署:Web应用程序?云服务(网络/工作者)? VM? –
@David Makogon - 这是一个连接到sql数据库的web应用程序。 –