NullReferenceException When SetLicense in Parallel.For

您好,
我在 webpage 的 page_load 使用 Parallel.For 去建立 License 、SetLicense 並建 PDF 物件,
會發生 NullReferenceException 的錯誤,
於 .(Stream )
於 .(String , Assembly )
於 Aspose.Pdf.License.SetLicense(String licenseName)

程式碼如下,
Parallel.For(0, 10, delegate (int i)
{
try
{
var lic = new License();
lic.SetLicense(“aspose.total.lic”);
var pdfDoc = new Document(@“c:\xx\node.pdf”);
Debug.WriteLine($"{i}:{pdfDoc.IsLinearized}");
}
catch (Exception ex)
{
Debug.WriteLine($"{i}:{ex}");
}

});
var pdfDocx = new Document(@"c:\xx\node.pdf");
Response.Write(pdfDocx.IsLinearized);

請問 Web 專案中,最好是在 Application_Start 中設定 License 嗎?
Thanks.

@rainmaker_ho,

我们设法在我们的环境中复制空指针错误。它已被记录在我们的问题跟踪系统中的票证ID PDFNET-44305中。我们已将您的信息与此故障单关联起来,并会通知您有关任何可用更新

@imran.rafique,
因為一般我們寫代碼時,都會先設定 license 再建立要使用的 aspose 物件,
請問在 web 專案中,需要在那裡設定 license 呢?
我有試過在 global’s application_start 中設定,而在 web form 中使用 aspose 物件是沒問題的。
所以web 專案的時機點是在 application_start 嗎?
謝謝您的幫忙。

@rainmaker_ho,

是的,Aspose API许可证应该应用于应用程序的某些公共区域。在Web应用程序中,推荐使用Global.asa文件中的启动应用程序事件。

@imran.rafique,
謝謝您的回覆,
真的還蠻神奇的,因為一般都先 Assign License 然後才開操作物件,
我試過在 application start 中設定,在 thread 中也可以 work 正常。
請問 pdf, words, cells 也都是如此嗎?
是否有線上文檔談到設定 License 這一部份呢?
另外,

請問如果一個 web 中有用到 words, pdf, cells 元件的話,
我是否要針對每個元件的 License 物件設定呢?

感謝您的幫忙。

@rainmaker_ho,

请注意,您需要为每个Aspose程序集为每个应用程序或进程设置一次许可证。每个Aspose程序集都有一个具有不同名称空间的许可证类,您需要调用SetLicense方法来应用许可证。请参阅以下帮助主题:将许可证应用于Aspose.Words for .NET API