COM Addin, in frame work 1.1 , C# and outlook 2003, it wast wroking fine i can able to send the mail with customised form , bu

HI

i have developed COM Addin,  in frame work 1.1 , C# and outlook 2003, it was wroking fine i can able to send the mail with customised form ,  but now i instal the FrameWork 2.0, it not working , i can not able to send the mails form now it is showing following error .

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'Microsoft.Office.Interop.Outlook.MailItemClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
   at OutlookMail.frmMailOutlook.btnSend_Click_1(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.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)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
SuperClockOutlook
    Assembly Version: 1.0.2183.26307
    Win32 Version: 1.0.2183.26307
    CodeBase: file:///C:/Program%20Files/Default%20Company%20Name/SuperClockOutlookSetup/SuperClockOutlook.dll
----------------------------------------
Extensibility
    Assembly Version: 7.0.3300.0
    Win32 Version: 7.00.9466
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Extensibility/7.0.3300.0__b03f5f7f11d50a3a/Extensibility.dll
----------------------------------------
Microsoft.Office.Interop.Outlook
    Assembly Version: 11.0.0.0
    Win32 Version: 11.0.5530
    CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Outlook/11.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Outlook.dll
----------------------------------------
office
    Assembly Version: 11.0.0.0
    Win32 Version: 11.0.5530
    CodeBase: file:///C:/WINDOWS/assembly/GAC/office/11.0.0.0__71e9bce111e9429c/office.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


with regards
chand




Answer this question

COM Addin, in frame work 1.1 , C# and outlook 2003, it wast wroking fine i can able to send the mail with customised form , bu

  • AndrewJones123543

    Do not use VS 2003 do debug .NET Fx 2.0 - use VS 2005 instead.

  • Tduffy77

    Interesting. Are you sure it is the .NET Fx 2.0 that broke your add-in (I suspect it may be incorrect type lib registration for outlook) What happens if you lock back to .NET Fx 1.1 (e.g. by placing and outlook.exe.config file). See this link for the content of the file. Just remember to remove the .config file after you have done the configuration - it is a bad practice to lock to .NET Fx 1.1 since it will prevent add-ins build on .NET Fx 2.0 from running.

    As a workaround (which is also a recommended practice) I would suggest to not cast your pointer to MailItemClass, but rather to a MailItem interface.



  • asum

    I think the problem I am having may be similiar to this but I am not sure about all the .Net framework talk. I am a bit of a novice. I have installed, uninstalled and installed again MS Office Small Business Edition 2003 and then Business Contact Manager Update for MS Office Outlook 2003. I have downloaded all the updates for the Office and the Contact Manager and when I try to create an email, Outlook gives me the error, MS Word - "Interface not Registered". So for some reason Outlook is thinking that MS Word is not installed or installed incorrectly, although, it is installed just fine and repaired. I have downloaded all updates including the .NET 2.0 framework. This problem just started today for some reason. Prior to today everything was working fine. Please help!. Thanks
  • Bobby Thurman

    Hi Misha,

    I have developed application for Outlook 2003 using Outlook Primary Interop Assemblies (Microsoft.Office.Interop.Outlook.dll). I am interating each mailitem in the inbox to do some processing. While I cast the MailItem of the inbox I get the following error:

    {"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook._MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}

    I have following block of code:

    int nCount = objFindItems.Count;

    for (int index = 1; index <= nCount; index++) // while (itrFindItems.MoveNext())

    {

    _MailItem objEmail = (_MailItem)(objFindItems[index]);

    }

    Please help me where I am missing.

    thanks in advance

    Sanjeev


  • Orogui

    The class is marked non-cocreateable. In 1.1 the framework would use an optimization to allow casting to the COM object in spite of this, but it was removed in 2.0. As Misha suggested, the solution is to use the interface rather than casting directly to the COM object.
  • Jason Nadrowski

    I have above problem because of typecasting
    Privicesly it was working fine in Frame work 1.1

    Microsoft.Office.Interop.Outlook.MailItemClass sendMial = (Microsoft.Office.Interop.Outlook.MailItemClass)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

    when i changed frame work 2.0 i had above problem , i solved flowing way

    Microsoft.Office.Interop.Outlook._MailItem sendMial = (Microsoft.Office.Interop.Outlook.MailItem)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

    chand.


  • Carlitos

    I am not sure how you have created objFindItems collection, but it looks like it does not entirely consists of mail items (it might contain appointments, tasks etc). If you try to cast something that is not a Mail Item to _MailItem interface - this is the error you are going to get. My suggestion to you is to check item's type before you do the cast.

  • caligula

    Thank you so much Micha!

    I have been struggling with same problem for some days now and when i used the interfaces instead of the classes (in my defence, it took over the code from somebody else ;-) my outlook add-in worked.

    I have one remaining problem, however. The outlook add-in works fine when i start outlook, but whe i try to debug using VS2003, Outlook crashes.

    Is there another way than using the config file to solve this problem

    Thanks,

    Maarten


  • LearnerNM

    Moved here from Visual Studio Team System General.

  • COM Addin, in frame work 1.1 , C# and outlook 2003, it wast wroking fine i can able to send the mail with customised form , bu