[C#] System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid) 해결 방법

Regsvr32 명령어

CoCreateInstance는 AxHost 네임스페이스의 CreateWithLicense 또는 CreateWithoutLicense 메서드와 함께 발생하는 경우가 있습니다. 해당 사항의 문제는 거의 다수가 OCX 또는 DLL 클래스가 등록되지 않아서 발생합니다.

Regsvr32 명령어를 통해 클래스를 등록하여 해결할 수 있습니다.

다음은 해당 문제가 발생하는 예제 자료를 몇 개 가져와 보았습니다. 공통적으로 발생하는 오류는 System.Runtime.InteropServices.COMException (0x80040154): 클래스가 등록되지 않았습니다. (예외가 발생한 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) 입니다.

System.Runtime.InteropServices.COMException (0x80040154): 클래스가 등록되지 않았습니다. (예외가 발생한 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
   위치: System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
   위치: System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
   위치: System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
   위치: System.Windows.Forms.AxHost.CreateInstance()
   위치: System.Windows.Forms.AxHost.GetOcxCreate()
   위치: System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
   위치: System.Windows.Forms.AxHost.CreateHandle()
   위치: System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   위치: System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   위치: System.Windows.Forms.AxHost.EndInit()

클래스가 등록되지 않았습니다
System.Runtime.InteropServices.COMException (0x80040154): 클래스가 등록되지 않았습니다. (예외가 발생한 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
   위치: System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
   위치: System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
   위치: System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
   위치: System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
   위치: System.Windows.Forms.AxHost.CreateInstance()
   위치: System.Windows.Forms.AxHost.GetOcxCreate()
   위치: System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
   위치: System.Windows.Forms.AxHost.CreateHandle()
   위치: System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   위치: System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   위치: System.Windows.Forms.AxHost.EndInit()

댓글