object that has been separated from its underlying RCW

Status
Not open for further replies.
J

j

Hi All,

what can be reason for this??

i'm trying to retrieve commandsBar, and once in a while got this

strange exception

within Outlook 2003.

System.Runtime.InteropServices.InvalidComObjectException: COM object

that has been separated from its underlying RCW cannot be used.

at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

Any ideas??
 
On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:
> Hi All,

> what can be reason for this??
> i'm trying to retrieve commandsBar, and once in a while got this
> strange exception
> within Outlook 2003.

> System.Runtime.InteropServices.InvalidComObjectException: COM object
> that has been separated from its underlying RCW cannot be used.
>    at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

> Any ideas??


Hi,

the reason for this is that you are using a COM object that is already

released.

Following code will throw that exception:

Outlook.MailItem mailItem = activeInspector.CurrentItem;

Marshal.ReleaseCOMObject(mailItem);

string mailItemSubject = mailItem.Subject;

Hope that helps,

Tobias
 
On Jul 30, 2:55 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:
> On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:
>
> > Hi All,

>
> > what can be reason for this??
> > i'm trying to retrieve commandsBar, and once in a while got this
> > strange exception
> > within Outlook 2003.

>
> > System.Runtime.InteropServices.InvalidComObjectException: COM object
> > that has been separated from its underlying RCW cannot be used.
> >    at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

>
> > Any ideas??


> Hi,

> the reason for this is that you are using a COM object that is already
> released.

> Following code will throw that exception:

> Outlook.MailItem mailItem = activeInspector.CurrentItem;
> Marshal.ReleaseCOMObject(mailItem);
> string mailItemSubject = mailItem.Subject;

> Hope that helps,
> Tobias


Thanks,

I see, however i access the Outlook excplorer's ui object.

You want to point that now even in Outlook (without any programming)

impossible to access the File Menu for example??

The Outlook is alive.

I don't understant this.

Please explain, thanks in advance.
 
On 30 Jul., 14:00, j <Evgeny...@gmail.com> wrote:
> On Jul 30, 2:55 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:

>
> > On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:

>
> > > Hi All,

>
> > > what can be reason for this??
> > > i'm trying to retrieve commandsBar, and once in a while got this
> > > strange exception
> > > within Outlook 2003.

>
> > > System.Runtime.InteropServices.InvalidComObjectException: COM object
> > > that has been separated from its underlying RCW cannot be used.
> > >    at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

>
> > > Any ideas??

>
> > Hi,

>
> > the reason for this is that you are using a COM object that is already
> > released.

>
> > Following code will throw that exception:

>
> > Outlook.MailItem mailItem = activeInspector.CurrentItem;
> > Marshal.ReleaseCOMObject(mailItem);
> > string mailItemSubject = mailItem.Subject;

>
> > Hope that helps,
> > Tobias


> Thanks,

> I see, however i access the Outlook excplorer's ui object.
> You want to point that now even in Outlook (without any programming)
> impossible to access the File Menu for example??
> The Outlook is alive.
> I don't understant this.

> Please explain, thanks in advance.


If that happens even when you just use Outlook, maybe it's another Add-

In causing the problem. Try disabling installed Add-Ins.

Tobias
 
On Jul 30, 3:03 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:
> On 30 Jul., 14:00, j <Evgeny...@gmail.com> wrote:

>
> > On Jul 30, 2:55 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:

>
> > > On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:

>
> > > > Hi All,

>
> > > > what can be reason for this??
> > > > i'm trying to retrieve commandsBar, and once in a while got this
> > > > strange exception
> > > > within Outlook 2003.

>
> > > > System.Runtime.InteropServices.InvalidComObjectException: COM object
> > > > that has been separated from its underlying RCW cannot be used.
> > > >    at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

>
> > > > Any ideas??

>
> > > Hi,

>
> > > the reason for this is that you are using a COM object that is already
> > > released.

>
> > > Following code will throw that exception:

>
> > > Outlook.MailItem mailItem = activeInspector.CurrentItem;
> > > Marshal.ReleaseCOMObject(mailItem);
> > > string mailItemSubject = mailItem.Subject;

>
> > > Hope that helps,
> > > Tobias

>
> > Thanks,

>
> > I see, however i access the Outlook excplorer's ui object.
> > You want to point that now even in Outlook (without any programming)
> > impossible to access the File Menu for example??
> > The Outlook is alive.
> > I don't understant this.

>
> > Please explain, thanks in advance.


> If that happens even when you just use Outlook, maybe it's another Add-
> In causing the problem. Try disabling installed Add-Ins.

> Tobias-



There is no other addIns.

My question is if for expample i execute the following line of code:

--> myExplorer is active explorer

Marshal.ReleaseCOMObject(myExplorer.CommandBars);

so now, i'll failed to work with Otulook's Menu ??
 
When the Interop wrapper for a COM object (RCW) is released it releases the

references to that object and you get that error when you try to then access

that object. That is caused by calling Marshal.ReleaseComObject() on the

object, or a similar call such as FinalReleaseComObject(), as explained by

Tobias.

One thing to be aware of is that if you have an Explorer object (or any

other) and you pass a copy of that Explorer to a procedure and in that

procedure you call one of the release methods the original object is

released, not just the copy passed to the procedure:

DoFoobarSub(_explorer);

if (_explorer.Caption == "Inbox") // fires RCW exception

{

}

private void DoFoobarSub(Outlook.Explorer exp)

{

// whatever

Marshal.ReleaseComObject(exp);

}

Any attempt to access _explorer after calling that DoFoobarSub() method will

fire an RCW exception.

In addition, although you say there are no other addins at all, you also

have to bear that in mind. If your managed code addin is not shimmed to

provide an exclusive AppDomain for it then things like this or any

exceptions or crashes in any managed code addin in the default AppDomain

will affect your addin. That's why shimming is so important for managed code

addins.

"j" <Evgeny.Br@gmail.com> wrote in message

news:435bd762-ea1d-442e-8aa4-9587c7f66d06@b15g2000yqd.googlegroups.com...

On Jul 30, 3:03 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:
> On 30 Jul., 14:00, j <Evgeny...@gmail.com> wrote:

>
> > On Jul 30, 2:55 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:

>
> > > On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:

>
> > > > Hi All,

>
> > > > what can be reason for this??
> > > > i'm trying to retrieve commandsBar, and once in a while got this
> > > > strange exception
> > > > within Outlook 2003.

>
> > > > System.Runtime.InteropServices.InvalidComObjectException: COM object
> > > > that has been separated from its underlying RCW cannot be used.
> > > > at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

>
> > > > Any ideas??

>
> > > Hi,

>
> > > the reason for this is that you are using a COM object that is already
> > > released.

>
> > > Following code will throw that exception:

>
> > > Outlook.MailItem mailItem = activeInspector.CurrentItem;
> > > Marshal.ReleaseCOMObject(mailItem);
> > > string mailItemSubject = mailItem.Subject;

>
> > > Hope that helps,
> > > Tobias

>
> > Thanks,

>
> > I see, however i access the Outlook excplorer's ui object.
> > You want to point that now even in Outlook (without any programming)
> > impossible to access the File Menu for example??
> > The Outlook is alive.
> > I don't understant this.

>
> > Please explain, thanks in advance.


> If that happens even when you just use Outlook, maybe it's another Add-
> In causing the problem. Try disabling installed Add-Ins.

> Tobias-



There is no other addIns.

My question is if for expample i execute the following line of code:

--> myExplorer is active explorer

Marshal.ReleaseCOMObject(myExplorer.CommandBars);

so now, i'll failed to work with Otulook's Menu ??
 
On Jul 30, 4:12 pm, "
<kenslo...@mvps.org> wrote:
> When the Interop wrapper for a COM object (RCW) is released it releases the
> references to that object and you get that error when you try to then access
> that object. That is caused by calling Marshal.ReleaseComObject() on the
> object, or a similar call such as FinalReleaseComObject(), as explained by
> Tobias.

> One thing to be aware of is that if you have an Explorer object (or any
> other) and you pass a copy of that Explorer to a procedure and in that
> procedure you call one of the release methods the original object is
> released, not just the copy passed to the procedure:

> DoFoobarSub(_explorer);
> if (_explorer.Caption == "Inbox") // fires RCW exception
> {

> }

> private void DoFoobarSub(Outlook.Explorer exp)
> {
>     // whatever
>     Marshal.ReleaseComObject(exp);

> }

> Any attempt to access _explorer after calling that DoFoobarSub() method will
> fire an RCW exception.

> In addition, although you say there are no other addins at all, you also
> have to bear that in mind. If your managed code addin is not shimmed to
> provide an exclusive AppDomain for it then things like this or any
> exceptions or crashes in any managed code addin in the default AppDomain
> will affect your addin. That's why shimming is so important for managed code
> addins.
> >

> http://www.slovaktech.com

> "j" <Evgeny...@gmail.com> wrote in message

> news:435bd762-ea1d-442e-8aa4-9587c7f66d06@b15g2000yqd.googlegroups.com...
> On Jul 30, 3:03 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:

>
> > On 30 Jul., 14:00, j <Evgeny...@gmail.com> wrote:

>
> > > On Jul 30, 2:55 pm, Tobias Böhm <boehm.t...@googlemail.com> wrote:

>
> > > > On 30 Jul., 13:30, j <Evgeny...@gmail.com> wrote:

>
> > > > > Hi All,

>
> > > > > what can be reason for this??
> > > > > i'm trying to retrieve commandsBar, and once in a while got this
> > > > > strange exception
> > > > > within Outlook 2003.

>
> > > > > System.Runtime.InteropServices.InvalidComObjectException: COM object
> > > > > that has been separated from its underlying RCW cannot be used.
> > > > > at Microsoft.Office.Interop.Outlook.ExplorerClass.get_CommandBars()

>
> > > > > Any ideas??

>
> > > > Hi,

>
> > > > the reason for this is that you are using a COM object that is already
> > > > released.

>
> > > > Following code will throw that exception:

>
> > > > Outlook.MailItem mailItem = activeInspector.CurrentItem;
> > > > Marshal.ReleaseCOMObject(mailItem);
> > > > string mailItemSubject = mailItem.Subject;

>
> > > > Hope that helps,
> > > > Tobias

>
> > > Thanks,

>
> > > I see, however i access the Outlook excplorer's ui object.
> > > You want to point that now even in Outlook (without any programming)
> > > impossible to access the File Menu for example??
> > > The Outlook is alive.
> > > I don't understant this.

>
> > > Please explain, thanks in advance.

>
> > If that happens even when you just use Outlook, maybe it's another Add-
> > In causing the problem. Try disabling installed Add-Ins.

>
> > Tobias-

>
>


> There is no other addIns.
> My question is if for expample i execute the following line of  code:
> --> myExplorer is active explorer
> Marshal.ReleaseCOMObject(myExplorer.CommandBars);

> so now, i'll failed to work with Otulook's Menu ??-



The AddIn provides an exclusive AppDomain. Also can please explain a

litle bit about shimming??

In my code i use Marshal.ReleaseCOMObject(...). I do it because of rpc

conneciton known issue limitation.

There is a command netstat -a

What should i see there?? How can i recognize open rpc conenction in

Outlook??

Many many thanks.
 
For information on netstat post in a networking group or google for the

information.

The RPC channel issue is real but you have to use common sense as to when

you call ReleaseComObject(). You do that mainly in loops on subsidiary

properties such as a mail item within a loop accessing the Items collection

of a folder. You never call that if you need to re-use the object again,

unless you explicitly instantiate another instance of the object afterwards.

You should always strive to declare objects at the lowest scope where they

will be needed, and release them when done with the objects, but don't

release objects you will have further use for.

Shimming provides a unique AppDomain for a managed code application. You

have to explicitly shim an addin or use VSTO, which does the shimming for

you. Either you write your own shimming code or you use the COM Shim Wizard

to create the shim for you. Shimming doesn't happen without an explicit shim

that loads your addin. If there is no shim then your code is running in a

common AppDomain and not an exclusive one.

"j" <Evgeny.Br@gmail.com> wrote in message

news:c695a83a-c7c3-44e2-9967-32f3dcd83073@r2g2000yqm.googlegroups.com...

<snip
The AddIn provides an exclusive AppDomain. Also can please explain a

litle bit about shimming??

In my code i use Marshal.ReleaseCOMObject(...). I do it because of rpc

conneciton known issue limitation.

There is a command netstat -a

What should i see there?? How can i recognize open rpc conenction in

Outlook??

Many many thanks.
 
On Jul 30, 6:45 pm, "
<kenslo...@mvps.org> wrote:
> For information on netstat post in a networking group or google for the
> information.

> The RPC channel issue is real but you have to use common sense as to when
> you call ReleaseComObject(). You do that mainly in loops on subsidiary
> properties such as a mail item within a loop accessing the Items collection
> of a folder. You never call that if you need to re-use the object again,
> unless you explicitly instantiate another instance of the object afterwards.

> You should always strive to declare objects at the lowest scope where they
> will be needed, and release them when done with the objects, but don't
> release objects you will have further use for.

> Shimming provides a unique AppDomain for a managed code application. You
> have to explicitly shim an addin or use VSTO, which does the shimming for
> you. Either you write your own shimming code or you use the COM Shim Wizard
> to create the shim for you. Shimming doesn't happen without an explicit shim
> that loads your addin. If there is no shim then your code is running in a
> common AppDomain and not an exclusive one.

> >

> http://www.slovaktech.com

> "j" <Evgeny...@gmail.com> wrote in message

> news:c695a83a-c7c3-44e2-9967-32f3dcd83073@r2g2000yqm.googlegroups.com...
> <snip
> The AddIn provides an exclusive AppDomain. Also can please explain a
> litle bit about shimming??

> In my code i use Marshal.ReleaseCOMObject(...). I do it because of rpc
> conneciton known issue limitation.
> There is a command netstat -a
> What should i see there?? How can i recognize open rpc conenction in
> Outlook??

> Many many thanks.


Thanks for such details explanation.

So, in case i'll not use VSTO and will develop shared AddIn, i'll to

build shim by myself??

There is no wizard for it?
 
As I said in my last post:

Either you write your own shimming code or you use the COM Shim Wizard to

create the shim for you. There is a COM Shim Wizard.

For VS 2005 you download it from MS, google for that, for VS 2008 it's

built-in.

As I also said my last post: VSTO does the shimming for you.

If shimming is the only reason you have not to use VSTO then you picked the

wrong reason.

"j" <Evgeny.Br@gmail.com> wrote in message

news:63d8cac9-125f-4a39-ac53-1688645567cb@t13g2000yqt.googlegroups.com...

<snip
Thanks for such details explanation.

So, in case i'll not use VSTO and will develop shared AddIn, i'll to

build shim by myself??

There is no wizard for it?
 
On Jul 30, 11:17 pm, "
<kenslo...@mvps.org> wrote:
> As I said in my last post:

>  Either you write your own shimming code or you use the COM Shim Wizardto
> create the shim for you. There is a COM Shim Wizard.

> For VS 2005 you download it from MS, google for that, for VS 2008 it's
> built-in.

> As I also said my last post: VSTO does the shimming for you.

> If shimming is the only reason you have not to use VSTO then you picked the
> wrong reason.

> >

> http://www.slovaktech.com

> "j" <Evgeny...@gmail.com> wrote in message

> news:63d8cac9-125f-4a39-ac53-1688645567cb@t13g2000yqt.googlegroups.com...
> <snip
> Thanks for such details explanation.
> So, in case i'll not use VSTO and will develop shared AddIn, i'll to
> build shim by myself??
> There is no wizard for it?


Thanks,

Does Shared Add-in wizard in VS-2005 create/handle the shim issue??

Thanks in advance.
 
Are you reading what I said at all?


> Either you write your own shimming code or you use the COM Shim Wizard to
> create the shim for you. There is a COM Shim Wizard.

> For VS 2005 you download it from MS, google for that, for VS 2008 it's
> built-in.


The shared addin wizard does just that, it creates a shared addin template.

If you want that addin shimmed you download the COM Shim Wizard and run

that.

"j" <Evgeny.Br@gmail.com> wrote in message

news:ccbc7c39-9c42-4355-98cd-0381e52e4327@c34g2000yqi.googlegroups.com...

<snip
Thanks,

Does Shared Add-in wizard in VS-2005 create/handle the shim issue??

Thanks in advance.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T COM object that has been separated from its underlying RCW Outlook VBA and Custom Forms 1
M MailItem object has no property for when a reply was sent Outlook VBA and Custom Forms 3
V Outlook Error The Attempted operation Failed. An Object Could Not be found Outlook VBA and Custom Forms 0
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
P Automate Outlook Start - No Active Explorer Object Found Using Outlook 10
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
J Outlook 2016 is killing me with object.links Outlook VBA and Custom Forms 2
S how to access the properties of a contact given distlist.member object Outlook VBA and Custom Forms 1
J An attempt operation failed. An object could not be found at line5. Outlook VBA and Custom Forms 2
R How can I retain embedded object with voting button reply? Using Outlook 5
G run-time 438: object doesn't support this property or method Using Outlook 2
B Task List in To-Do Bar 'The operation failed. An object could not be found' Using Outlook 3
A vb6 run time error 5 when Outlook 2007 Explorer object displayed Outlook VBA and Custom Forms 1
P Problem with a Search-Object resulting from an AdvancedSearch Outlook VBA and Custom Forms 2
T How to get Inspector object from Window handle Outlook VBA and Custom Forms 2
M Outlook Contact Object: Is there a "last accessed" date-time prope Outlook VBA and Custom Forms 3
M Cannot Send - "Operation failed. An object cannot be found" BCM (Business Contact Manager) 4
K How to disconnect Application.COMAddIns.Item().Object? Outlook VBA and Custom Forms 4
S RDOMail object is not working in different thread. Outlook VBA and Custom Forms 13
G Error in Outlook Object Model with redemption and google apps prem Outlook VBA and Custom Forms 3
C Unable to cast object of type 'System.Int32' to type 'System.Byte[ BCM (Business Contact Manager) 1
S UserProperties of MailItem object. Outlook VBA and Custom Forms 3
P UserProperty of mail object problem while dealing with custom fold Outlook VBA and Custom Forms 2
S How to get RFC822 format message from the MailItem object. Outlook VBA and Custom Forms 4
B Compile error: Object required Outlook VBA and Custom Forms 2
S Strange Behaviour of Explorer Object. Outlook VBA and Custom Forms 1
R Unable to cast COM object" error Outlook VBA and Custom Forms 2
R Unable to cast COM object" error Outlook VBA and Custom Forms 5
R destroying Explorer object pointers on shutdown Outlook VBA and Custom Forms 2
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
CWM550 This rule has a condition that the server cannot process? Using Outlook 1
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
e_a_g_l_e_p_i Has nobody used Office 2021 enough to help me or have you given up on me.......lol Using Outlook 1
O Comma Separated Values.ADR and A file error has occurred in the translator Using Outlook 6
D We're sorry but outlook has run into an error Using Outlook 6
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
N Outlook Has Become Sluggish Using Outlook 12
C Your mailbox has been temporarily moved ... Using Outlook 2
W Receiving mail for account that has been deleted Using Outlook 2
H Outlook 2003 find by "has attachment" Using Outlook 1
W Looks like the folder below has been deleted: "iCloud\Calendar" Using Outlook 1
oliv- determine to which address an email has been sent Outlook VBA and Custom Forms 3
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
O Outlook 2016 has "Outlook 2015" files Using Outlook 2
M Outlook 2016 bottom reading pane has disappeared Using Outlook 2
G Download pdf attachments only if email subject has one of words Outlook VBA and Custom Forms 8

Similar threads

Back
Top