We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to fix the ThreadStateException (ActiveX control cannot be instantiated) exception when converting HTML to PDF?

How to fix the ThreadStateException (ActiveX control cannot be instantiated) exception when converting HTML to PDF?

 

In the HTML to PDF conversion process, the HTMLConverter throws an exception with the message "ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."

The HTMLConverter internally makes use of the MSHTML.dll that can run only in the STA mode. Running the application in the MTA mode leads to this exception. 

This can be fixed by any of the following ways:

  1. In the ASP.NET applications, add 'AspCompat=true' in the @page directive.
  2. In ASP.NET MVC, windows or web services and console applications make use of the following code snippet:

 

Article ID: Published Date: Last Revised Date: Platform: Control:
6394 02/25/2016 02/25/2016 ASP.NET Web Forms PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.