Application: Windows form Application,
Server: 2016 windows server
Plateform: server 64 bit

Our Window form application is throwing following exception only on one server for specific feature to access on click of button(all other features are accessible and working fine on this same server for same application).

Note: Same winform application with all same feature are working fine on other two server(with same configuration).

Exception:
System.Runtime.InteropServices.COMException (0x80040154): Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at SOLVWorkSpace.frmSurLtp.InitializeComponent()
at SOLVWorkSpace.frmSurLtp..ctor()

Exception 1 Message:Exception has been thrown by the target of an invocation.
Stack trace:at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at SOLVWorkSpace.utilities.openNonDuplicateForm(Type newForm, Form senderForm, Boolean openForm, String customWindowBarText, String priceListKey)
at SOLVWorkSpace.frmMdiMain.openForm_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Exception 2 Message:Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Stack trace: at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at SOLVWorkSpace.frmSurLtp.InitializeComponent()
at SOLVWorkSpace.frmSurLtp..ctor()

Kindly suggest any idea or clue why is it throwing.

Thanks in advance

Hi @fullstackvale ,
>>Exception 2 Message:Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Cooldadtx has performed a detailed analysis of exception one. Then there are the following reasons for exception two:
The system uses a third-party COM component that is not registered.
You can use the system registration command to register components.
If the COM component used has been registered, but this type of error is still reported. There are many 64-bit systems in this case, and the project "target platform" configuration needs to be modified to "x86".
Best Regards,
Daniel Zhang

Hi @fullstackvale ,
Have you tried the method I mentioned above and what result?
Best Regards,
Daniel Zhang

Your SOLVWorkSpace.utilities.openNonDuplicateForm method is trying to dynamically create an instance of a type and the constructor call is failing. We have no way of knowing why this is failing so we cannot answer your question. Look at the code for the given method. Find where it is dynamically creating an instance of a type instead of using a regular new expression. This is the call that is failing. You can look at the InnerException property of the thrown exception and it will often give you the actual exception that triggered the call to fail and this will provide more information to you.

Just guessing but since it is relying on dynamic creation instead of new then it is likely trying to load an assembly programmatically at runtime rather than having a compile time dependency. The assembly is either not being found or is the wrong version so the construction of the type fails. I would verify this by looking at the inner exception and then ensure that all the dependencies your code relies on is either in the application directory or installed (if you rely on third party products as well).

There are many 64-bit projects in this case, and the project "target platform" build configuration needs to be modified to "x86".
Thanks.