昨天在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的概念需要熟悉,其它的线程,线程同步,线程池等概念需要再巩固一下了
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。