vb6/vb.net puzzle

S

Sean Kirkpatrick

I've found a puzzle with my legacy app and my new .Net dll.

I have defined an abstract base class

Public MustInherit Class AbstractFoos
Inherits CollectionBase

Public MustOverride Sub Append(ByRef poField As ACIndex)
Public MustOverride Sub Delete(ByRef psName As String)

' other defs
End Class

I've defined a concrete class

Public Class ConcreteFoos
Inherits AbstractFoo

Public Overrides Sub Append(ByRef poField As ACIndex)
... stuff ...
End Sub
Public Overrides Sub Delete(ByRef psName As String)
... stuff ...
End Sub

End Class

Public Class Bar
dim moFoos as ConcreteFoos

public readonly property get Foos as ConcreteFoos
Get
return moFoos
End Get
End Property
End Class

So ConcreteFoos provides the implementations necessary, plus has all of
the nifty CollectionBase stuff, such as Count. Bar is the ultimate
provider of ConcreteFoos via the Foos property. So far, so good.

In my vb6 app, I create a Bar and try to access the Count property of
the Foos property - should work just fine.

dim myBar as new Bar
... add some Foos ...
debug.print "Count is " & myBar.Foos.Count

This ALWAYS returns 0, regardless of the number of ConcreteFoos actually
exist. However, if I do this

dim myBar as new Bar
... add some Foos ...

dim myFoos as ConcreteFoos
set myFoos = myBar.Foos
debug.print "Count is " & myFoos.Count

I get the correct number of ConcreteFoos.

I've rewritten the test code in .Net and it works correctly there.

Am I missing something obvious? Does this make sense?

As an aside, this is the app I was asking about earlier this morning vis
a vis debugging between VB6 and .Net IDEs. The simple test program as
well as my main legacy app both crash the IDEs when I try to step across
the IDE boundary, and also when I try to step into the .Net dll from the
the compiled executable.

I'm really puzzled. I wanna believe that this is problem with my code -
I can fix it if it is, but the fact that the code fails one way but
works the other makes me think there's something funny about the COM
Interop layer.

Thanks for any insights!


Sean
 
P

Peter Huang [MSFT]

Hi Sean,

From your description, it seems that the member moFoos in not initialized
when declaration, so when did it initialized(i.e. Created)
Public Class Bar
dim moFoos as ConcreteFoos
public readonly property get Foos as ConcreteFoos
Get
return moFoos
End Get
End Property
End Class

I think maybe the different creating procedure cause the different
behavior. Because VB.NET and VB is totally a different programming language
except they have the similar syntax, in nature, VB.NET is kind of .NET
language which have the similar syntax with VB6. So call it from unmanaged
code /managed code may differ.

So far I think you may try to add Trace code in every necessary method call
which will be called when you trying to call .Count property.
e.g. Write to a file as a log.

If you still have any concern, can you help to build a simple reproduce
sample for us to reproduce/troubleshooting the problem.
Thanks for your efforts!



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top