[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

COM object that has been separated from its underlying RCW cannot be used (IADsUser

Hayato Iriumi

2/10/2007 1:12:00 AM

Hello, folks.
I have an issue using ActiveDS COM object from .NET Framework 2.0.
When I access one of the properties of IADsUser, I get the following
error.

"COM object that has been separated from its underlying RCW cannot be
used"

This doesn't happen all the time, but it happens intermittenly. Here
is the code.

Dim userObject As IADsUser =
oDomainUtils.UserContainer(User.StaffLoginID, User.StaffDomain, False)
_AccountDisabled = userObject.AccountDisabled ' <-- Error happens here
intermittently

So oDomainUtils.UserContainer function returns IADsUser obviously and
the property of userObject (type of IADsUser) AccountDisabled is
accessed, then the error happens intermittenly. We have had this code
for a while and released our product and this error never happened
in .NET Framework 1.1. The tendency we are observing here is that it
happens when I first open the application. When I try it again, the
error doesn't happen.

I have done some Googling and came across fair amount of hits on "COM
object that has been separated from its underlying RCW cannot be used"
error, nothing was specific to ActiveDS COM object. Has anyone
experienced something like this?

2 Answers

Patrick Steele

2/11/2007 1:49:00 PM

0

In article <1171069892.578037.327130@s48g2000cws.googlegroups.com>,
hiriumi@gmail.com says...
> Hello, folks.
> I have an issue using ActiveDS COM object from .NET Framework 2.0.
> When I access one of the properties of IADsUser, I get the following
> error.
>
> "COM object that has been separated from its underlying RCW cannot be
> used"

The times I got this in the past was when the COM object had gone away
while the .NET object (the RCW) hadn't. In this context, I had to do
interop with VB6 objects (single threaded) across different threads
(don't ask -- it's a long story). It meant we really had to keep track
of which thread created these objects since they were STA and only lived
on the thread they were created on. If that thread ever went away or we
allowed it to end, the COM object went away even if the RCW that .NET is
using to talk to it was still around (not garbage collected).

You're not doing any multithreading, are you? If so, check if your COM
objects are STA and if so, make sure you're keeping that thread alive
and only accessing them from the thread that created them.

--
Patrick Steele
http://weblogs.asp.n...

Hayato Iriumi

2/12/2007 5:22:00 PM

0

Hello, Patrick. Thank you very much for taking your time to share your
experience. I really appreciate it.

On Feb 11, 5:49 am, Patrick Steele <patr...@mvps.org> wrote:
> In article <1171069892.578037.327...@s48g2000cws.googlegroups.com>,
> hiri...@gmail.com says...
>
> > Hello, folks.
> > I have an issue using ActiveDS COM object from .NET Framework 2.0.
> > When I access one of the properties of IADsUser, I get the following
> > error.
>
> > "COM object that has been separated from its underlying RCW cannot be
> > used"
>
> The times I got this in the past was when the COM object had gone away
> while the .NET object (the RCW) hadn't. In this context, I had to do
> interop with VB6 objects (single threaded) across different threads
> (don't ask -- it's a long story). It meant we really had to keep track
> of which thread created these objects since they were STA and only lived
> on the thread they were created on. If that thread ever went away or we
> allowed it to end, the COM object went away even if the RCW that .NET is
> using to talk to it was still around (not garbage collected).
>
> You're not doing any multithreading, are you? If so, check if your COM
> objects are STA and if so, make sure you're keeping that thread alive
> and only accessing them from the thread that created them.
>
> --
> Patrick Steelehttp://weblogs.asp.n...