asp.net調用xps對象GetFixedDocumentSequence出現異常

來源:互聯網
上載者:User

標籤:asp.net 調用dll   sta   


  昨天在web端調用別人寫的word處理dll時,出現了

‘The invocation of the constructor on type ‘System.Windows.Documents.DocumentReference‘ that matches the specified binding constraints threw an exception.‘ Line number ‘2‘ and line position ‘21‘.

問題,這個問題我寫了樣本程式是沒有問題的(cs端),經過別人的指點,在拋出異常的地方找到的innerexception是sta的問題,這個具體沒有把資訊保留下來.

   根據innerexception的提示,發現了xps對象和其中的方法是STA的,但是aspx頁面是MTA,經過幾番周折找到遇到一樣問題的人:http://stackoverflow.com/questions/24058070/how-to-read-a-xps-file-in-c-sharp-using-asp-net

  問題真的是一樣的,然後按照裡面提供的連結(第二個)添加

<%@ Page Language="C#" AspCompat="true" %>

  我試過了,完全沒有用.httphandler 自己還不熟,於是寫了一個線程來調用出力xps文檔的那個方法,於是成功搞定,程式碼範例如下:

 

//....//調用的地方System.Threading.Thread thread =                new System.Threading.Thread(               new System.Threading.ParameterizedThreadStart(ThreadMethod));            thread.Start(value);            thread.Join();//等待結束//....
//線程函數private void ThreadMethod(object parameter){    //這裡寫的就是對xps處理的代碼}

總結:STA、MTA的概念需要熟悉,其它的線程,線程同步,線程池等概念需要再鞏固一下了

本文出自 “越努力,越幸運” 部落格,請務必保留此出處http://actor.blog.51cto.com/1764681/1594057

asp.net調用xps對象GetFixedDocumentSequence出現異常

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.