Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Component Services / November 2004

Tip: Looking for answers? Try searching our database.

ServicedComponent: COM object separated from its underlying RCW?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jo Siffert - 10 Nov 2004 16:24 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.