본문 바로가기

.NET/C#

IIS System.Runtime.InteropServices.COMException (0x80005000)

http://blog.naver.com/techshare/100148750375

에서 퍼온 글입니다.

 

IIS Recycle 을 하는 코드를 만들어 두었는데,

string appPoolPath = "IIS://" + Environment.MachineName + "/W3SVC/AppPools/DefaultAppPool";
DirectoryEntry appPoolEntry = new DirectoryEntry(appPoolPath);

appPoolEntry.Invoke("Recycle");

특정 PC 에서는 다음과 같은 오류가 발생했습니다.

System.Runtime.InteropServices.COMException (0x80005000): 不明なエラー (0x80005000)
   場所 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   場所 System.DirectoryServices.DirectoryEntry.Bind()
   場所 System.DirectoryServices.DirectoryEntry.get_NativeObject()
   場所 System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
   ...[생략]...
   場所 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

원인을 알 수 없어 웹 검색을 해보았는데, 참 원인도 다양한 많은 사연들이 있었지만 제 경우에 해당하는 것은 없었습니다.

그런데, 문득 문제를 일으킨 PC 가 "Windows 7"이라는 것과 예전에 작업했던 내용이 떠오르면서 단서를 얻을 수가 있었습니다.

IIS Metabase 와 ServerManager 개체 활용
; http://www.sysnet.pe.kr/2/0/973

그렇습니다. 해당 컴퓨터에서는 "IIS 6 Metabase Compatibility" 구성 요소가 설치되어 있지 않았기 때문에 Recycle 명령을 실행시에 그와 같은 오류가 발생한 것입니다. ^^

그래서, 운영체제 버전이 6 이상인 경우에는 다음과 같은 코드를 수행하도록 확장하는 것으로~~~ 이슈 종료!

// Microsoft.Web.Administration.dll
ServerManager svr = new ServerManager();

ApplicationPool appPool = svr.ApplicationPools[appPoolId];
if (appPool != null)
{
    appPool.Recycle();
}