Visual Studio Developer Center >
Visual Studio Forums
>
Visual Studio Tools for Office
>
generates COM Exception {"The operation failed."} error code -2147467259 if outlook is running and excuting window vsto application from dev environment
generates COM Exception {"The operation failed."} error code -2147467259 if outlook is running and excuting window vsto application from dev environment
- I had an window for which is interacting with the Application object of outlook. When i tried to run my application and outlook is also running, it generate the exception while trying to get the
application object. I tried below both the way to get the application object. the running object and new object.
to get a new object _outlookApplication = new Application(); to get a running object _outlookApplication = Marshal.GetActiveObject("Outlook.Application") as Applicationon some of the pcs it is even running. i dont find any configuration changes between them. I am using windows2008 server OS with VS2008 and VSTO3.0 on development environment.
Answers
- Hi,
for me that sounds that you run Outlook under Administrator UserAccount .
And the Application runs at a different Account/Environment.
Outlook is a single App instance.
You try to create/attach to the Outlook process from cross domain.
It seems that you run your Visual Studio as Administrator.
When you compile your AddIn - it's registered only for the current user - in your case the Administrator
When you start your Outlook as normal user - you won't have the Addin.
So maybe it's a configuration problem.
What I've lerned in the past is, dont run visual Studio as Administrator.
So - if you write code that causes problems while you require access e.g. to Registry or Filesystem where you won't have - you can see it in the development stage - not when it is deployed.
Maybe try to setup a Virtual Machine and try to run your Outlook in a Testenvironment.
For Development - I would try not to use different Useraccounts.
So - I'm not sure if that helps - but so I'm out of Ideas here.
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]- Marked As Answer byvijay kumar anand Friday, November 06, 2009 12:58 PM
All Replies
- Hello,
I notice that Application in your code may be not Outlook application rather Window forms application. So, I think you could explicitly write Outlook.Application. In my side, I have made a test, and it works fine. Code like this,
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mi = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
object missing = Type.Missing;
mi.Display(missing);
or
Outlook.Application app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
Outlook.MailItem mi1 = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
object missing = Type.Missing;
mi1.Display(missing);
Try this again, and Does it work?
By the way, this forum is mainly targeted at VSTO technology. VSTO is a technology for extending the UI of Office 2003 and 2007 applications in the forum of Add-ins and document-level customizations. As you mentioned, it seems to be little related to VSTO technology rather an Windows Form. The forum's PLEASE READ FIRST explains what VSTO forum is for.
Best regards,
Bessie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Hi Zhao,
thankx for your respnose. Since i am having an outlook add-in and its supporting win form app which runs in seperate. When i am using "new OutlookApplication()" by win form app to get the outlook application object. it generate the exception on some system if outlook is also running, but not on all system. even if i create the exe and try the same with exe it works fine. this problem till the time coming on few of pcs and with dev envrionment. Initially i try to put it on winform thread, but feel it can be mostly faced by vsto developers so i put in on this. - Hi Vijay,
when your form is opened inside the same namespace of your addin, you can access the Application Object like this:
Globals.ThisAddin.Application
If the Form is in another NameSpace, you should pass the Application Object as Contructor to your Form.
e.g. FormX form = new FormX(Globals.ThisAddin.Application)
Remember the App Object as Variable in Form.cs
Hope this helps,
greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de] - Hi Helmut,
You guys are doing great, but i think my problem is little bit different.
Actually we are having two seperate apps. One is my Add-in app which is running in seperate thread with outlook and the Other is seperate win form apps which is just accessing the outlook application object by "_outlookApplication = new Application();".
The winform application taking the application at start as it can be started seperate at any time by user and take the outlook application object. It synch with the services and download the data and update in outlook pst. so its not the issue with namespace.
While on some PC if we run with outlook, it started sucessfully, but on some PC it generate the above exception.
Hope you understand my problem. - Hi,
then first check if Outlook is already running and attach to the Process instead of creating a new Application Object.
Here's a sample with a Word Instance.
However - if you ar using the ApplicationObject from Outside the AddIN- the Application is not safe and can cause Securitywarnings.
Greets - Helmut
// is there an existing application object ?if (Process.GetProcessesByName("WINWORD").Count() > 0) {// use the GetActiveObject method to attach an existing application objectapp = Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;}if (app == null){// create a new instanceapp = new Microsoft.Office.Interop.Word.Application();}
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de] - Hi Helmut,
Thanks for your response, but its also not working. The COMException it shows is 'MK_E_UNAVAILABLE' which might be the integrity level issue it looks like asi am using windows 2008 server which is basically using the vista integrity mechanism.
If i am running the outlook as "Run as Administrator" option then only it get its object by dev. environment. So dev environment is running on higher IL and my outlook is running on medium IL as it looks like.
Do you have any idea to to run the outlook default in higher IL? - Hi,
for me that sounds that you run Outlook under Administrator UserAccount .
And the Application runs at a different Account/Environment.
Outlook is a single App instance.
You try to create/attach to the Outlook process from cross domain.
It seems that you run your Visual Studio as Administrator.
When you compile your AddIn - it's registered only for the current user - in your case the Administrator
When you start your Outlook as normal user - you won't have the Addin.
So maybe it's a configuration problem.
What I've lerned in the past is, dont run visual Studio as Administrator.
So - if you write code that causes problems while you require access e.g. to Registry or Filesystem where you won't have - you can see it in the development stage - not when it is deployed.
Maybe try to setup a Virtual Machine and try to run your Outlook in a Testenvironment.
For Development - I would try not to use different Useraccounts.
So - I'm not sure if that helps - but so I'm out of Ideas here.
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]- Marked As Answer byvijay kumar anand Friday, November 06, 2009 12:58 PM


