Today, I am starting my journey in MSDN blog . I hope, this will help people who are facing this problem.
As a support engineer I have been troubleshooting many issues on daily basis. I am going to address an issue which is very common these days as people are migrating from 32 bit machine to 64 bit machines, They are facing some compatibility issues with the application build on 32 bit platform. I am gonna talk about one of such common problem and its different solutions.
Lets take a simple scenario which is very common across the companies.
You have ASP.net application which is hosted on 32 bit machine. This web site also reference a third party DLL which is also build in 32 bit. Every thing was working fine. Now I decided to host this web site on 64 bit machine. Suddenly I realize my application has broken, its not working and start throwing the following error.
“Retrieving the COM Class factory for component with Glass ID, CLS ID failed due to the following error 80040154.”
Thumb Rule: You can not load a 32 bit Dll in a 64 bit process space.
This problem can be solved in different ways and totally depends upon your requirements. Same time each approach has its own pros and cons which needs to be examine carefully before adopting any approach.
The best solution of this problem is
- Build the referenced DLL's on 64 bit platform
Most of the time either you are using a third party dll's which you can not build on 64 bit platform or you have other limitations which stops you to build the references dll's' on 64 bit platform. Now in both the scenarios you are not left with much options. Lets see what are the options you have.
- Run the IIS host process(w3wp.exe) in 32 bit mode
- Create a wrapper of your dll's and host this wrapper dll's in COM+
- Upgrade your IIS6.0 to IIS 7.0 where you can run a particular app pool( w3wp.exe) in 32 bit mode
As I mentioned before that all the above approaches has its own pros and cons and I would not like to go in to details about it. I would like to give you step by step process to execute the above approaches.
Run the IIS host process(w3wp.exe) in 32 bit mode
This is very simple approach where you will run two commands on command prompt and your application will start working. The problem with this approach is that after this change of IIS, all of your web site will work under 32 bit app pool.
Here are the command you need to run on your command prompt.
ASP.NET 2.0, 32-bit version
To run the 32-bit version of ASP.NET 2.0, follow these steps:
1.Click Start, click Run, type cmd, and then click OK.
2.Type the following command to enable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
3.Type the following command to install the version of ASP.NET 2.0 (32-bit) and to install the script maps at the IIS root and under:
4.Make sure that the status of ASP.NET version 2.0.50727 (32-bit) is set to Allowed in the Web service extension list in Internet Information Services Manager.
ASP.NET 2.0, 64-bit version
To run the 64-bit version of ASP.NET 2.0, follow these steps:
1.Click Start, click Run, type cmd, and then click OK.
2.Type the following command to disable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0
3.Type the following command to install the version of ASP.NET 2.0 and to install the script maps at the IIS root and under:
4.Make sure that the status of ASP.NET version 2.0.50727 is set to Allowed in the Web service extension list in Internet Information Services Manager.
These steps are taken from the following KB. Please check it for more details.
Create a wrapper of your dll's and host this wrapper dll's in COM+
In this solution, we will create a wrapper for the 32 bit dll's and will host it in COM+. ASP.NET application will communicate to 32 bit dll's VIA COM+ (dllhost.exe). The main advantage of this approach is that you can still use your 32 bit dll's inside the 64 bit IIS process but you have to take care of the COM+ complexity.
There are basically four steps which you have to perform:
1) Create COM+ Service component.
2) Give your assembly a strong name.
3) Host your wrapper under COM+
4) Call the COM+ component in your ASP.net application
You can find first three steps in the following KB. It will give you a step by step process.
Once you register the component with COM+, you have to use the following steps to use it in your ASP.net application
- Add the reference of COM+ component in your ASP.net project
- Add the following line in your code
Using <ServicedCOM>; //( ServicedCOM is the name of your COM+ component)
- Now create an object as you create for any other class in .net and call the respective functions. for example
ServicedCOM.SimpleTrans ob = new ServicedCOM.SimpleTrans(); // again i am taking ServicedCOM as an example.
Upgrade your IIS6.0 to IIS 7.0 where you can run a particular app pool( w3wp.exe) in 32 bit mode
Now the last option we have is to upgrade the from IIS 6.0 to IIS 7.0. The advantage of this approach is that you can run a specific app pool in 32 bit mode but to achieve this you have to migrate your operating system to Windows server 2008 (Longhorn) as IIS 7.0 is available only with W2k8 or VISTA.
If you are ready to upgrade/migrate your OS, here are the steps you have to take to resolve the issue.
- First install the IIS7.0 from the windows components/Server Roles
- Open IIS 7.0 manager
- Right click on “Application Pools” and Click “Add Application Pool”
- Give it a name & change the version of .net as per your requirement.
- After creating your new web app, right click on it and open “Advanced Settings”
- Change the setting “Enable 32-Bit Applications”, to True like...
- Now open the virtual directory of your application and change the app pool as follows
I hope, this post will add some value in case you are facing similar problem. If you have any question or doubts, Please feel free to write me. I will try my best to help you.
Disclaimer: I work at Microsoft. Everything here, though, is my personal opinion and is not read or approved by Microsoft before it is posted. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.