没有注册类别 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))

时间:2022-09-01 07:49:59
异常如下所示,可能是某个COM组件未注册(B超),但是项目下的dll文件我都测试了,始终是抛出这个异常。
未处理 System.Runtime.InteropServices.COMException
  Message="没有注册类别 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))"
  Source="System.Windows.Forms"
  ErrorCode=-2147221164
  StackTrace:
       在 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()
       在 WindFormsApplication.Frm_Person.InitializeComponent() 位置 E:\一体机\WindFormsApplication\WindFormsApplication\WindFormsApplication\Frm_Person.Designer.cs:行号 681
       在 WindFormsApplication.Frm_Person..ctor() 位置 E:\一体机\WindFormsApplication\WindFormsApplication\WindFormsApplication\Frm_Person.cs:行号 154
       在 WindFormsApplication.userLogin.button3_Click(Object sender, EventArgs e) 位置 E:\一体机\WindFormsApplication\WindFormsApplication\WindFormsApplication\userLogin.cs:行号 39
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 WindFormsApplication.Program.Main() 位置 E:\一体机\WindFormsApplication\WindFormsApplication\WindFormsApplication\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

13 个解决方案

#1


的确是com主件未注册的问题, com组件并不需要出现在你的程序目录下,所以光查找这是没用的,
你需要找到
System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)中的clsid,找一个可以运行程序的机器,打开注册表查找此clsid,找到后可以发现是那个com/ole组件,并可以获得路径,拷贝到自己机器程序的目录注册一下就行了

#2


在注册表里咋查找呀???

#3


兄弟,你这个问题解决了没?我也遇到了

#4


同问。

#5


解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#6


楼上正解,大赞!!!
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#7


楼上正解,大赞!!!
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#8


确实是好办法
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#9


为啥我的不行

#10


能否详细说明?

#11


引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.


果然有牛人!!!

#12


我的也不行,可能是com不一样,导致原因也不同吧

#13


引用 5 楼 kim 的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

大哥。。。我是英文版的,不知道对应的是啥啊。能不能说一下啊

#1


的确是com主件未注册的问题, com组件并不需要出现在你的程序目录下,所以光查找这是没用的,
你需要找到
System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)中的clsid,找一个可以运行程序的机器,打开注册表查找此clsid,找到后可以发现是那个com/ole组件,并可以获得路径,拷贝到自己机器程序的目录注册一下就行了

#2


在注册表里咋查找呀???

#3


兄弟,你这个问题解决了没?我也遇到了

#4


同问。

#5


解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#6


楼上正解,大赞!!!
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#7


楼上正解,大赞!!!
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#8


确实是好办法
引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

#9


为啥我的不行

#10


能否详细说明?

#11


引用 5 楼  的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.


果然有牛人!!!

#12


我的也不行,可能是com不一样,导致原因也不同吧

#13


引用 5 楼 kim 的回复:
解决办法:在项目属性里设置“生成”=>“目标平台”为x86而不是默认的ANY CPU.

大哥。。。我是英文版的,不知道对应的是啥啊。能不能说一下啊