您好,登錄后才能下訂單哦!
昨天在web端調(diào)用別人寫的word處理dll時,出現(xiàn)了
'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端),經(jīng)過別人的指點,在拋出異常的地方找到的innerexception是sta的問題,這個具體沒有把信息保留下來.
根據(jù)innerexception的提示,發(fā)現(xiàn)了xps對象和其中的方法是STA的,但是aspx頁面是MTA,經(jīng)過幾番周折找到遇到一樣問題的人:http://stackoverflow.com/questions/24058070/how-to-read-a-xps-file-in-c-sharp-using-asp-net
問題真的是一樣的,然后按照里面提供的鏈接(第二個)添加
<%@ Page Language="C#" AspCompat="true" %>
我試過了,完全沒有用.httphandler 自己還不熟,于是寫了一個線程來調(diào)用出力xps文檔的那個方法,于是成功搞定,代碼示例如下:
//.... //調(diào)用的地方 System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ParameterizedThreadStart(ThreadMethod)); thread.Start(value); thread.Join();//等待結(jié)束 //....
//線程函數(shù) private void ThreadMethod(object parameter) { //這里寫的就是對xps處理的代碼 }
總結(jié):STA、MTA的概念需要熟悉,其它的線程,線程同步,線程池等概念需要再鞏固一下了
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。