我正在使用 Microsoft Outlook 视图控件,试图了解它的功能,但我并没有走得太远。它在设计时出现,但在运行时只给出“E_CLASSNOTREG”异常。我如何找出它在抱怨什么课程?
我刚刚创建了一个winform项目,将控件添加到工具箱中,然后将其拖到窗体中。我在设计时看到了我的 Outlook 收件箱。它添加了以下代码:
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.axViewCtl1 = new AxMicrosoft.Office.Interop.OutlookViewCtl.AxViewCtl();
((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).BeginInit();
this.SuspendLayout();
//
// axViewCtl1
//
this.axViewCtl1.Enabled = true;
this.axViewCtl1.Location = new System.Drawing.Point(384, 184);
this.axViewCtl1.Name = "axViewCtl1";
this.axViewCtl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axViewCtl1.OcxState")));
this.axViewCtl1.Size = new System.Drawing.Size(192, 192);
this.axViewCtl1.TabIndex = 0;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(1093, 633);
this.Controls.Add(this.axViewCtl1);
this.Name = "Form1";
((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).EndInit();
this.ResumeLayout(false);
}
然后我运行它,它死在我身上:
System.Runtime.InteropServices.COMException occurred
Message="Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
Source="System.Windows.Forms"
ErrorCode=-2147221164
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
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 Sample.OutlookForm.Form1.InitializeComponent() in D:\source\tests\OutlookView\Sample.OutlookForm\Form1.Designer.cs:line 50
InnerException:
...例外是在 EndInit()。
另外,另一个奇怪的事情是,每次我在设计器中单击控件时,Visual Studio 都会冻结一段时间,有时短至 30 秒,有时我必须杀死 Outlook 任务才能让 VS 响应。
我在 Windows 7 x64 上运行带有最新补丁/SP 的 VS 2008,并且我有安装了所有最新补丁和服务包的 Office 2007。
为什么这在设计时对我有用,但在运行时却失败了?我怎样才能找到它正在寻找的未注册的内容?