Hi,
I have defined the following ServicedComponent that currently does nothing.
< _
ClassInterface(ClassInterfaceType.None), _
Guid("D374C669-3779-45da-83F4-5D2279F0355B") _
> _
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,
Jo
Robert Jordan - 10 Nov 2004 16:38 GMT
Hi,
> I have defined the following ServicedComponent that currently does nothing.
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
Rob
Jo Siffert - 10 Nov 2004 18:33 GMT
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
> Hi,
>
[quoted text clipped - 31 lines]
> bye
> Rob
Robert Jordan - 10 Nov 2004 18:47 GMT
> 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?
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
Rob
Jo Siffert - 11 Nov 2004 08:03 GMT
>> Hi Robert,
>>
[quoted text clipped - 5 lines]
> No, they aren't. Do you implement IEnumerable somewhere?
> In you previous post I saw that you don't:
No, I did not. Do I have to even if my class does not have collection
semantics?
Thanks,
Jo
> Public Class FooManager
> Inherits ServicedComponent
[quoted text clipped - 18 lines]
> bye
> Rob
Jo Siffert - 11 Nov 2004 15:07 GMT
Hi,
it seems to have been a bug in the Framework - after installing SP1
everything works fine...
Thanks though,
Jo
>>> Hi Robert,
>>>
[quoted text clipped - 34 lines]
>> bye
>> Rob
Robert Jordan - 11 Nov 2004 15:37 GMT
Hi Jo,
> it seems to have been a bug in the Framework - after installing SP1
> everything works fine...
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
Rob