首页 > 解决方案 > 如何解决此问题:未注册 COM 异常类(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))?

问题描述

我试图制作一个将发送邮件的程序,但是当我尝试发送它时,我只需要解决这个问题:

COM 异常类未注册(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))

这是我的代码:

Outlook.Application app = new Outlook.Application();
 Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);

            mailItem.Subject = "Password recovery";
            mailItem.To = MailTxt.Text;
            mailItem.HTMLBody = "Your new password is: " + RecoveryNewPW + ". <br/> If you want to change the password, you need to do following:<ul><li>Login and go to settings tab.</li><li>Write old password in the first textbox.</li><li>Write the new password in the second textbox</li><li>Write the new password again in the third textbox</li><li>Done!</li></ul>";
            mailItem.Send();
            MessageBox.Show("Sent!");

我感谢您的帮助!我知道这个问题已经存在于这个网站上,但我无法通过其他问题解决这个问题。

标签: c#winformsoutlook

解决方案


如果您安装了 32 位版本的 Office,则需要在 Visual Studio 中打开“属性”屏幕并从“配置”下拉列表中选择“所有配置”,然后从“平台目标”下拉列表中选择“x86”。

设置为 x86

您可以通过安装位置来判断您拥有的 Office 版本。如果它安装在“Program Files (x86)”中,那么它是 32 位的。如果它在“程序文件”中,则它是 64 位版本。


推荐阅读