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;
                    doc.CleanAndRepair();

                    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
0
: 544 At:- 12/12/2020 12:26:30 PM
C# ASP.NET MVC






1 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

solved-error-an-attempt-was-made-to-load-program-with-incorrect-format-min.png

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"

image-second-min.png

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






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

Full Name *

Email *




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