Friday, October 05, 2007

I'll Need This Later Note To Self: .Net and MAPI/CDO Don't Mix

mstehle: The CDOs and CDONTS of Messaging Development - FYI: Why are MAPI and CDO 1.21 not supported in managed (.NET) code?

"The issue of using MAPI or (most commonly) CDO 1.21 in managed (.NET) code is one that comes back to us a lot on the Messaging Developer Support team. Both the messaging technologies in question and the .NET framework have been around for many years at this point. As well have the KB articles that state the supportability [GD: i.e. that MS doesn't support Managed usage of MAPI/CDO1.21] of Outlook and Exchange APIs in managed code. There are three main contributors to steady stream of cases we see – even today – where customers are using MAPI and CDO 1.21 in managed code…

...

Okay, I've heard that before so why exactly is using MAPI or CDO 1.21 not supported in managed code?

MAPI has its own memory management model that conflicts with and is incompatible with the .NET runtime. This the primary reason that MAPI and CDO 1.21 are not supported running in a .NET process. The common symptoms you will see are seemingly random Access Violations and very often memory leaks (especially with CDO 1.21). There is no methodology for avoiding or managing these symptoms by using interop libraries or managing references in a particular fashion in your .NET code – it just won't work.

The trap is that CDO 1.21 and .NET can "appear" to work and you can get pretty far in your dev cycle before you run into problems. Many times we see this come up in soon after a solution is released to production, in late cycle performance testing, or in a pilot program. ...

...

Fine, I won't use .NET and MAPI or CDO 1.21 in the same process but I still need to write this application – now what?

The simple answer is you either need to not use .NET or not use MAPI or CDO 1.21. So how do you make that decision?

...

...If you really feel that CDO 1.21 or MAPI is your best option based on the business requirements of what your application must do then by all means use CDO 1.21 – just plan to use it *out of process* from your .NET code."

So in short create an out of proc ActiveX EXE in VB6 (or C++, etc) to contain your MAPI/CDO code and access it via interop...

2 comments:

SteveGibson said...

I've been using the Redemption library, specifically the Redemption Data Objects (RDO). RDO is intended to be the functional equivalent to CDO 1.21 and works great with my managed C# apps :)

Greg said...

Thank you for that! It's great to hear that Redemption works well in .Net

I've been using Redemption for years (since 2.0 ;) in my VB6 apps. That library just ROCKS, doesn't it? And Dmitry provides outstanding support...

I was thinking of moving beyond Redemption and closer to MAPI, etc when I moved my apps to the Outlook 2007 & managed world.

I'm going to have to rethink that now.

Looks like I'll be with Redemption well into the future.

And that's an okay thing. :)


BTW, have you looked at/used his Outlook and Office Spy products? They are must have if you're doing Outlook/MAPI/CDO & Office Object Model development...