asp.net调用xps对象GetFixedDocumentSequence出现异常
昨天在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
问题真的是一样的,然后按照里面提供的链接(第二个)添加
<%@PageLanguage="C#"AspCompat="true"%>
我试过了,完全没有用.httphandler 自己还不熟,于是写了一个线程来调用出力xps文档的那个方法,于是成功搞定,代码示例如下:
//....//调用的地方System.Threading.Threadthread=newSystem.Threading.Thread(newSystem.Threading.ParameterizedThreadStart(ThreadMethod));thread.Start(value);thread.Join();//等待结束//....
//线程函数privatevoidThreadMethod(objectparameter){//这里写的就是对xps处理的代码}
总结:STA、MTA的概念需要熟悉,其它的线程,线程同步,线程池等概念需要再巩固一下了
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。