How to solve error "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"?

Hello, When I am using below simple C# code to untidy my XML string, but when executing locally it is working fine, but on server I am getting below error

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at TidyManaged.Interop.PInvoke.tidyCreate()
   at TidyManaged.Document.FromString(String htmlString)

Here is my C# code, which works fine locally.

               using (Document doc = Document.FromString(HTMLStr))

                    doc.OutputXml = true;
                    doc.OutputHtml = false;
                    doc.UseXmlParser = true;

                    doc.IndentWithTabs = true;
                    doc.IndentBlockElements = AutoBool.Yes;
                    doc.IndentAttributes = true;

                    cleanXML = doc.Save();

How to resolve this error?

I have checked my platform Build on Visual Studio, it is selected as "Any CPU", I have deployed this code on IIS and using .NET MVC web-application.

Asked by:- bhanu
: 6125 At:- 12/12/2020 12:26:30 PM

2 Answers
profileImage Answered by:- vikas_jk

You need to enable your web-application application pool to run 32-bit applications.

If you can login into Windows Server, then follow these steps to resolve issue.

  1. Open IIS on Windows Server
  2. Click on "Application Pools"
  3. Select your web-application's application pool (on which you are getting error)
  4. On the right-hand side inside "Actions" pane, select "Advanced Settings"
  5. In "General" -> "Enable 32-bit application" -> Set it to "True".
  6. Click "Ok" and then restart website


It should solve your issue.

Solution 2

In Visual Studio, you may need to change build to "Platform target" -> Select "x86", instead of Any CPU (if you are using any 32-bit library)

Select Project from Solution Explorer-> Right-click on it -> Select "Properties" -> Select "Build" -> in "Platform Target" -> Select "x86" from dropdown OR check "Prefer 32 bit", if it is allowed.

Solution 3

If you are getting this issue, when trying to Run web-application in browser ( IIS Express), then you may need to select 64-bit IIS.

Navigate to, Tools -> Options -> Projects and Solutions -> Web Projects -> Select "Use the 64 bit version of IIS Express" and Click "Ok"


At:- 12/14/2020 11:30:46 AM Updated at:- 11/23/2022 5:52:27 AM
Thanks, Enabling 32 bit applications on IIS worked for me. 0
By : bhanu - at :- 12/23/2020 2:39:54 PM

profileImage Answered by:- neena

In Solution Explorer -> Right-click on it -> Select "Properties" -> Select "Build"  you are using Any CPU, you might encounter this issue if the Prefer 32-bit option is checked:


Make sure you uncheck this option.


If you are getting this error in .NET Core, try to download 32-bit .netcore runtime, and having your project target x86.

At:- 11/23/2022 7:56:23 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use