標籤: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出現異常