Unable to Instantiate Outlook Object from Visual Studio 2008 on Vista with UAC ON?

Having problems in instantiating a new Outlook object from VS 2008(Windows Form Application) when running on Vista with UAC ON? Getting weird errors similar to the ones below?

System.Runtime.InteropServices.COMException was unhandled
  Message="Creating an instance of the COM component with CLSID {0006F03A-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80010001."
  Source="MyApp"
  ErrorCode=-2147418111

This error was when Outlook was NOT running and I tried to debug my application from Visual studio 2008.

System.Runtime.InteropServices.COMException was unhandled
  Message="Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005."
  Source="MyApp"
  ErrorCode=-2146959355

This error was when Outlook was already running and I tried to debug my application from Visual studio 2008. In both cases I got the error when I tried to instantiate a new object of the Outlook.Application.

oApp = new Outlook.Application

Using the Err.exe to get more details on the 80010001 and the 80080005 we get the following details:

# for hex 0x80010001 / decimal -2147418111 :
  DBG_EXCEPTION_NOT_HANDLED                                     ntstatus.h    
# Debugger did not handle the exception.
  RPC_E_CALL_REJECTED                                           winerror.h    
# Call was rejected by callee.
# 2 matches found for "80010001"

# for hex 0x80080005 / decimal -2146959355 :
  CO_E_SERVER_EXEC_FAILURE                                      winerror.h    
# Server execution failed
# 1 matches found for "80080005"

Why would we be getting a RPC_E_CALL_REJECTED or CO_E_SERVER_EXEC_FAILURE? In my case this was happening because of the difference in Integrity Level of the two processes(Outlook.exe and devenv.exe)

The Visual Studio 2008 was being "Run as administrator" which makes it run in High IL and Outlook was by default running in Medium IL and this was causing the errors. The solution is run both the processes in the same IL.

How can you check the Integrity Level of a process? Use Process Explorer(Click on the View menu -> Select Columns->Process Image Tab and check Integrity Level)

Hope this helps!