0

I have a console app, which is using Microsoft.Web.Administration to remotely manage IIS on remote server (I used this https://stackoverflow.com/questions/22458410/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 (https://stackoverflow.com/questions/1036856/retrieving-the-com-class-factory-for-component-with-clsid-xxxx-failed-due-to-t?rq=1), 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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.