all groups > dotnet component services > november 2004 >
You're in the

dotnet component services

group:

ServicedComponent: COM object separated from its underlying RCW?


ServicedComponent: COM object separated from its underlying RCW? Jo Siffert
11/10/2004 5:24:10 PM
dotnet component services:
Hi,

I have defined the following ServicedComponent that currently does nothing.

< _
ClassInterface(ClassInterfaceType.None), _
Guid("D374C669-3779-45da-83F4-5D2279F0355B") _
[quoted text, click to view]
Public Class BarEnumerator
Inherits ServicedComponent
Implements IEnumerator

Private ReadOnly Property Current() As Object Implements
IEnumerator.Current
End Property

Private Function MoveNext() As Boolean Implements IEnumerator.MoveNext
End Function

Private Sub Reset() Implements IEnumerator.Reset
End Sub

Public Overloads Sub Dispose()
End Sub
End Class

It is deployed as a server application. I can instantiate this class and
invoke Current. When I call MoveNext(), the following exception is thrown:

System.Runtime.InteropServices.InvalidComObjectException : COM object
that has been separated from its underlying RCW can not be used.

Stack Trace:
at System.Runtime.Remoting.Messaging.StackBuilderSink
.PrivateProcessMessage(
MethodBase mb, Object[] args, Object server,
Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink
.SyncProcessMessage(
IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(
IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy
.PrivateInvoke(MessageData& msgData, Int32 type)
at System.Collections.IEnumerator.MoveNext()

For me this sounds like an Apartment-related problem, but I do not know
how to fix it using ES...

Thanks,
Re: ServicedComponent: COM object separated from its underlying RCW? Robert Jordan
11/10/2004 5:38:16 PM
Hi,

[quoted text, click to view]

I'm clueless about VB.NET, so I don't understand why
the methods/properties can be empty.

The following C#-Enumerator works as expected:

public class TestEnumerator : ServicedComponent, IEnumerator {
readonly string[] strings = new string[] {"hello", "world"};
IEnumerator innerEnum;

public TestEnumerator() {
innerEnum = strings.GetEnumerator();
}

public object Current {
get {
return innerEnum.Current;
}
}

public void Reset() {
innerEnum.Reset();
}

public bool MoveNext() {
return innerEnum.MoveNext();
}
}

bye
Re: ServicedComponent: COM object separated from its underlying RCW? Jo Siffert
11/10/2004 7:33:12 PM
Hi Robert,

even with your dummy implementation I get the same exception. However,
when I do not implement IEnumerator and use the class interface instead,
everything works fine.
Are there any restrictions with the IEnnumerator/IEnumVARIANT-RCW?

Thanks,
Jo

[quoted text, click to view]
Re: ServicedComponent: COM object separated from its underlying RCW? Robert Jordan
11/10/2004 7:47:42 PM
[quoted text, click to view]

No, they aren't. Do you implement IEnumerable somewhere?
In you previous post I saw that you don't:

Public Class FooManager
Inherits ServicedComponent
Implements IFooManager

....
Function List( _
ByVal parentId As Int32 _
) As IEnumerator Implements IFooManager.List
Return New FooEnumerator(parentId, m_dbCfg)
End Function

You are suppose to:

Public Class FooManager
Inherits ServicedComponent
Implements IFooManager, IEnumerable <---

Function GetEnumerator ....
Return New FooEnumerator(parentId, m_dbCfg)

bye
Re: ServicedComponent: COM object separated from its underlying RCW? Jo Siffert
11/11/2004 9:03:28 AM
[quoted text, click to view]
No, I did not. Do I have to even if my class does not have collection
semantics?

Thanks,
Jo

[quoted text, click to view]
Re: ServicedComponent: COM object separated from its underlying RCW? Jo Siffert
11/11/2004 4:07:13 PM
Hi,

it seems to have been a bug in the Framework - after installing SP1
everything works fine...

Thanks though,
Jo

[quoted text, click to view]
Re: ServicedComponent: COM object separated from its underlying RCW? Robert Jordan
11/11/2004 4:37:52 PM
Hi Jo,

[quoted text, click to view]

Glad to hear it works! I tested the enumerator with SP1. No chance
to discover that myself, because my "production" components running
on a machine w/out SP1 don't implement an enumerator.

bye
AddThis Social Bookmark Button