2016-07-30 29 views
2

我有一个基于websocket的文本编辑器,我为大学项目编写。在我的本地机器上正常工作,但部署到Azure时出现错误。Azure应用程序提供HRESULT E_FAIL已从调用COM组件返回

将html转换为rtf时出现问题,我使用了herehere的混合代码。这需要在一个单线程单元中使用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); 
+0

你在哪里部署:Web应用程序?云服务(网络/工作者)? VM? –

+0

@David Makogon - 这是一个连接到sql数据库的web应用程序。 –

回答

0

访问出的进程COM在Web应用程序沙箱的限制。

看我其他的答案在这里为完整的详细信息: https://stackoverflow.com/a/38622209/4148708

+0

感谢您的输入,我已阅读Azure沙箱上的文章,这非常有帮助。我认为这意味着我将不得不查看另一个托管解决方案?我是新来的Azure,请原谅我的无知。 –

+0

正确。查看Azure云服务(Web角色)或虚拟机(IaaS)。下面是将Web项目转换为Web角色(云服务)的便捷指南 - https://azure.microsoft.com/zh-CN/documentation/articles/vs-azure-tools-migrate-publish-web -app到云服务/ – evilSnobu

相关问题