views:

42

answers:

1

I have some code:

Outlook.Application outLookApp = new Outlook.Application();
Outlook.Inspector inspector = outLookApp.ActiveInspector();
Outlook.NameSpace nameSpace = outLookApp.GetNamespace("MAPI");
Outlook.MAPIFolder inbox = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
String sCriteria = "[SenderEmailAddress] = '[email protected]'";
Outlook.Items filteredItems = inbox.Items.Restrict(sCriteria);
// totaly sure that count > 0;
Outlook.MailItem item = filteredItems[1];

In the last line I have error: "Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Outlook.MailItem'. An explicit conversion exists (are you missing a cast?)". I don't know why. Previous I used VisualStudio 2010 but my trial has expired. Is there any hope to run this on SharpDevelop?

A: 

This doesn't look like a SharpDevelop error, it looks like you just need a cast. Try this:

Outlook.MailItem item = (Outlook.MailItem)filteredItems[1];

(this is assuming that the objects in filteredItems are actually of this type. You may want to test if this is the case before this assignment.)

Also, you could use Visual Studio 2010 Express - http://www.microsoft.com/express/

Graham Clark
Thanks this helps me. But I am pretty sure that this code works in VS without a cast. Is there any difference between this tools?
Sebastian
The error you're showing comes from the compiler, not SharpDevelop or Visual Studio. Could it be you're using the Mono framework with SharpDevelop? This would use a different compiler that might give different messages. Or maybe you just have different settings for the same compiler across the two development environments.
Graham Clark