Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServerManager.OpenRemote error 80040154 CLSID {2b72133b-3f5b-4602-8952-803546ce3344} in ASP.NET MVC 4

I have a console app, which is using Microsoft.Web.Administration to remotely manage IIS on remote server (I used this Credentials for ServerManager.OpenRemote - modified ahadmin properties, opened TCP port 135. I also used impersonation). Everything works fine - I can remotely create Sites and App Pools and so on.

But when I'm trying to do the same thing in ASP.NET MVC 4 app, I get this error:

System.Runtime.InteropServices.COMException: Retrieving the COM class factory for remote component with CLSID {2B72133B-3F5B-4602-8952-803546CE3344} from machine "remoteServerIP" failed due to the following error: 80040154 "remoteServerIP".

I know many people get this error, and I saw a lot of posts about it, but nothing worked for me. I tried switching my MVC app to platform target X86 (Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154), on remote machine I enabled full permissions for both HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID{2b72133b-3f5b-4602-8952-803546ce3344} and HKEY_CLASSES_ROOT\CLSID{2b72133b-3f5b-4602-8952-803546ce3344} for the account that I'm using to impersonate. The problem seems to be in some difference between MVC and console apps, but I can't figure out what it is.

I'm on Windows 7 x64, remote server - windows server 2008 R2 x64. There's IIS 7.5 on both machines.

like image 964
myroslava72 Avatar asked Feb 10 '15 13:02

myroslava72


1 Answers

I found the solution. The issue was the fact that my MVC app was using a wrong version of Microsoft.Web.Administration.dll.

When I was debugging console app, I was able to get a list of sites from local IIS using this code

ServerManager serverManager = new ServerManager();

and a list of sites from remote IIS using this code

ServerManager serverManager = ServerManager.OpenRemote("remoteServerIpAddress");

and everything was OK. Then I put exactly the same code in an MVC app, and when I tried to get a list of sites from remote IIS I got the exception from the question. When trying to get a list of sites from local IIS, I got websites from IIS Express. Server Manager seemed to connect to IIS Express instead of full IIS, but I didn't pay much attention to this at first. Unfortunately.

Accidentally I found this post Microsoft.Web.Administration.ServerManager looking in wrong directory for IISExpress applicationHost.config, from where I found out that

If the application, in which you are using Microsoft.Web.Administration ..., is running on IISExpress, it will always fallback to Microsoft.Web.Administration version 7.9.0.0 due to an assembly redirect in the aspnet.config in the IIS express.

I was using IIS Express to debug, and it redirected me to wrong version of Microsoft.Web.Administration.dll - 7.9.0.0, and I needed 7.0.0.0, which is used by full IIS. So I hosted my MVC app on full local IIS, debugged it there and it worked! I successfully retrieved a list of sites from remote IIS. Hope it helps someone.

like image 160
myroslava72 Avatar answered Sep 22 '22 00:09

myroslava72