473,624 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET COLLECTION VB6 COM

Hi,

I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of
the VB6 hassles with cloning and serializing an object). All my
classes I need cloneable/serializable are now in a VB.NET class that exposes
those objects to COM perfectly. However I ran into a problem because some
of these objects requires a Collection. When I compile this project with
the VB.NET Collection exposed for a property, I get a compile time error
that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried
using VBA.CollectionC lass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport, PA
Nov 20 '05 #1
16 2585
Ben

See if this helps

http://support.microsoft.com/?kbid=323737

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
Hi Ben,

I agree with Mattias's suggestion.
The problem may be caused by a known issue when passing a collection from a
.NET-Connected Application to Visual Basic 6.0 Components.

Did Mattias's link help you?
If you have any related question, please feel free to let me know.

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.
--------------------
From: "Ben Hannon" <ha****@brodart .com>
Subject: VB.NET COLLECTION VB6 COM
Date: Tue, 14 Oct 2003 09:30:54 -0400
Lines: 16
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eQ************ *@TK2MSFTNGP10. phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:146549
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Hi,

I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of
the VB6 hassles with cloning and serializing an object). All my
classes I need cloneable/serializable are now in a VB.NET class that exposesthose objects to COM perfectly. However I ran into a problem because some
of these objects requires a Collection. When I compile this project with
the VB.NET Collection exposed for a property, I get a compile time error
that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried
using VBA.CollectionC lass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport , PA


Nov 20 '05 #3
Actually, those links helped me decide to kill trying to pass the VBA
Collection since I can't serialize it. What I decided to do instead is to
create a VB.NET collection with the ArrayList class and expose the methods
needed for COM Interop. Everything works perfectly when running the Class
as a Console App (clone works perfectly). However, when I compile it as a
DLL and try to use it in my VB6 app, when I try to clone an object I get the
error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of
the VB6 hassles with cloning and serializing an object). All my
classes I need cloneable/serializable are now in a VB.NET class that exposes those objects to COM perfectly. However I ran into a problem because some
of these objects requires a Collection. When I compile this project with
the VB.NET Collection exposed for a property, I get a compile time error
that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried
using VBA.CollectionC lass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport, PA

Nov 20 '05 #4
Actually, those links helped me decide to kill trying to pass the VBA
Collection since I can't serialize it. What I decided to do instead is to
create a VB.NET collection with the ArrayList class and expose the methods
needed for COM Interop. Everything works perfectly when running the Class
as a Console App (clone works perfectly). However, when I compile it as a
DLL and try to use it in my VB6 app, when I try to clone an object I get the
error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of
the VB6 hassles with cloning and serializing an object). All my
classes I need cloneable/serializable are now in a VB.NET class that exposes those objects to COM perfectly. However I ran into a problem because some
of these objects requires a Collection. When I compile this project with
the VB.NET Collection exposed for a property, I get a compile time error
that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried
using VBA.CollectionC lass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport, PA

Nov 20 '05 #5
I did a little more looking into this bug and discovered it is occurring when I try
to deserialize my Memory Stream:

Public Function CloneMe(ByVal Data As Object) As Object

Dim myMemoryStream As New System.IO.Memor yStream

Dim MyFormatter As New BinaryFormatter

Try

MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity)

MyFormatter.Ser ialize(myMemory Stream, Data)

MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " & myMemoryStream. Position)

myMemoryStream. Seek(0, SeekOrigin.Begi n)

MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " & myMemoryStream. Position)

***CloneMe = MyFormatter.Des erialize(myMemo ryStream)

MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " & myMemoryStream. Position)

myMemoryStream. Close()

myMemoryStream = Nothing

Catch

MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf & Err.Description , MsgBoxStyle.Cri tical)

CloneMe = Nothing

End Try

End Function

The red/asterisked line above is the line that generates this error.

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message news:eS******** ******@tk2msftn gp13.phx.gbl...
Actually, those links helped me decide to kill trying to pass the VBA
Collection since I can't serialize it. What I decided to do instead is to
create a VB.NET collection with the ArrayList class and expose the methods
needed for COM Interop. Everything works perfectly when running the Class
as a Console App (clone works perfectly). However, when I compile it as a
DLL and try to use it in my VB6 app, when I try to clone an object I get the
error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of
the VB6 hassles with cloning and serializing an object). All my
classes I need cloneable/serializable are now in a VB.NET class that

exposes
those objects to COM perfectly. However I ran into a problem because some
of these objects requires a Collection. When I compile this project with
the VB.NET Collection exposed for a property, I get a compile time error
that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried
using VBA.CollectionC lass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport, PA


Nov 20 '05 #6
Hi Ben,

Based on my understanding, you want to pass a VB6 object to the CloneMe
method to be serialized.
I think it is not a proper method to do so.
Since when interoperation between VB and .NET, the Object passed from VB to
.NET is an COM object.
The serialization implement between COM and .NET is different, that is to
say if you serialize a COM object
in .NET, the .NET framework will not know how to serialize the object.

In my test the error will occur at the line below.

MyFormatter.Ser ialize(myMemory Stream, Data)
Because .NET framework do not know how to serialize the Object Data.

This is my sample code, is that what you are doing in your code?
If you have any question, please feel free to let me know.

[VB6]
Private Sub Command1_Click( )
Dim so As New ClassLibrary3.C lass1
Text1.Text = "1000"
Dim obj As Object
obj = so.CloneMe(ByVa l Text1)
MsgBox obj.Text
End Sub

[ClassLibrary3.C lass1]
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
Imports System.Runtime. InteropServices
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream()

Dim MyFormatter As New BinaryFormatter ()
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
End Class
BTW
Are your VB.NET dll named as TartanCls?
If so, you may need to place it in the same directory as the VB6 Exe file
or you can use the command line below to register the VB.NET classlibrary.
regasm /codebase ClassLibrary3.d ll

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.

--------------------
From: "Ben Hannon" <ha****@brodart .com>
References: <eQ************ *@TK2MSFTNGP10. phx.gbl> <eS************ **@tk2msftngp13 .phx.gbl>Subject: Re: VB.NET COLLECTION VB6 COM
Date: Thu, 16 Oct 2003 11:59:55 -0400
Lines: 243
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_ 0092_01C393DD.0 3CE8EF0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <##************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147338
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I did a little more looking into this bug and discovered it is occurring when I tryto deserialize my Memory Stream:
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream
Dim MyFormatter As New BinaryFormatter
Try
MsgBox("Befo re Serialization. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity)MyFormatter.Se rialize(myMemor yStream, Data)
MsgBox("Afte r Serialization. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)myMemoryStream .Seek(0, SeekOrigin.Begi n)
MsgBox("Afte r Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)***CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("Afte r Deserialization . " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)myMemoryStream .Close()
myMemoryStre am = Nothing
Catch
MsgBox("Erro r occurred in sub CloneMe." & vbCrLf & vbCrLf & Err.Description , MsgBoxStyle.Cri tical)CloneMe = Nothing
End Try
End Function
The red/asterisked line above is the line that generates this error.
Ben Hannon
"Ben Hannon" <ha****@brodart .com> wrote in message

news:eS******** ******@tk2msftn gp13.phx.gbl...
Actually, those links helped me decide to kill trying to pass the VBA
Collection since I can't serialize it. What I decided to do instead is to create a VB.NET collection with the ArrayList class and expose the methods needed for COM Interop. Everything works perfectly when running the Class as a Console App (clone works perfectly). However, when I compile it as a
DLL and try to use it in my VB6 app, when I try to clone an object I get the error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
> Hi,
>
> I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of > the VB6 hassles with cloning and serializing an object). All my
> classes I need cloneable/serializable are now in a VB.NET class that

exposes
> those objects to COM perfectly. However I ran into a problem because some > of these objects requires a Collection. When I compile this project with > the VB.NET Collection exposed for a property, I get a compile time error > that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried > using VBA.CollectionC lass, but everytime I try to create a new object in > VB6, the object stays equal to nothing (Doesn't create).
>
> Ben Hannon
> Williamsport, PA
>
>



Nov 20 '05 #7
Peter,

Actually, it's not a VB6 object. The classes that will be
serialized/Cloned are written in VB.NET and compiled as a DLL with COM
Interop. All of the serialization is done internally in the DLL so that the
..NET runtime is being used, not VB6 runtime and is only serializing the .NET
class (nothing passed from VB6). Serializing the object works perfectly,
the part that barfs is when I try to deserialize the memorystream that was
just serialized along with Deserializing a binary file. Deserialize errors:
"Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." I added some more code in my DLL to
loop through the AppDomain.Curre ntDomain.GetAss emblies and msgbox the
assembly info to check if the assembly was loaded and it was, however when I
tried
Path.GetDirecto ryName(System.R eflection.Assbl y.GetEntryAssem bly().Location)
to get the DLL's path, that errored with "Object reference not set to an
instance of an object" which tells me that the current loaded assembly it
not defaulted at that point. Looks like I may have to load the assembly a
second time before deserializing? All of this code however works when
compiled as a .NET Console App. My next thing I'm gonna try is copying the
DLL/TLB to my VB6 app and reference it to there, maybe that will fix the
problem. If you would like to see my code, I can post it.

Ben
"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:sI******** ******@cpmsftng xa06.phx.gbl...
Hi Ben,

Based on my understanding, you want to pass a VB6 object to the CloneMe
method to be serialized.
I think it is not a proper method to do so.
Since when interoperation between VB and .NET, the Object passed from VB to NET is an COM object.
The serialization implement between COM and .NET is different, that is to
say if you serialize a COM object
in .NET, the .NET framework will not know how to serialize the object.

In my test the error will occur at the line below.

MyFormatter.Ser ialize(myMemory Stream, Data)
Because .NET framework do not know how to serialize the Object Data.

This is my sample code, is that what you are doing in your code?
If you have any question, please feel free to let me know.

[VB6]
Private Sub Command1_Click( )
Dim so As New ClassLibrary3.C lass1
Text1.Text = "1000"
Dim obj As Object
obj = so.CloneMe(ByVa l Text1)
MsgBox obj.Text
End Sub

[ClassLibrary3.C lass1]
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
Imports System.Runtime. InteropServices
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream()

Dim MyFormatter As New BinaryFormatter ()
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
End Class
BTW
Are your VB.NET dll named as TartanCls?
If so, you may need to place it in the same directory as the VB6 Exe file
or you can use the command line below to register the VB.NET classlibrary.
regasm /codebase ClassLibrary3.d ll

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.

--------------------
From: "Ben Hannon" <ha****@brodart .com>
References: <eQ************ *@TK2MSFTNGP10. phx.gbl> <eS************ **@tk2msftngp13 .phx.gbl>
Subject: Re: VB.NET COLLECTION VB6 COM
Date: Thu, 16 Oct 2003 11:59:55 -0400
Lines: 243
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_ 0092_01C393DD.0 3CE8EF0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <##************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147338
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I did a little more looking into this bug and discovered it is occurring

when I try
to deserialize my Memory Stream:
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream
Dim MyFormatter As New BinaryFormatter
Try
MsgBox("Befo re Serialization. " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity)
MyFormatter.Se rialize(myMemor yStream, Data)
MsgBox("Afte r Serialization. " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "

& myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream .Seek(0, SeekOrigin.Begi n)
MsgBox("Afte r Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
***CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("Afte r Deserialization . " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "

& myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream .Close()
myMemoryStre am = Nothing
Catch
MsgBox("Erro r occurred in sub CloneMe." & vbCrLf & vbCrLf & Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
The red/asterisked line above is the line that generates this error.
Ben Hannon
"Ben Hannon" <ha****@brodart .com> wrote in message

news:eS******** ******@tk2msftn gp13.phx.gbl...
Actually, those links helped me decide to kill trying to pass the VBA
Collection since I can't serialize it. What I decided to do instead is to create a VB.NET collection with the ArrayList class and expose the methods needed for COM Interop. Everything works perfectly when running the Class as a Console App (clone works perfectly). However, when I compile it as a DLL and try to use it in my VB6 app, when I try to clone an object I
get the error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutral , PublicKeyToken= null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart .com> wrote in message
news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
> Hi,
>
> I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of > the VB6 hassles with cloning and serializing an object). All my
> classes I need cloneable/serializable are now in a VB.NET class that
exposes
> those objects to COM perfectly. However I ran into a problem because some > of these objects requires a Collection. When I compile this project with > the VB.NET Collection exposed for a property, I get a compile time error > that VB cann't find Type Library "Microsoft.Visu alBasic". I even tried > using VBA.CollectionC lass, but everytime I try to create a new object in > VB6, the object stays equal to nothing (Doesn't create).
>
> Ben Hannon
> Williamsport, PA
>
>

Nov 20 '05 #8
Hi Ben,

If your project is somewhat large, you may post a simple sample to
demostrate what you want to do and reproduce the problem.
Based on my understanding, you want to call an method of an managed DLL,
and the method will do the clone in the DLL.
e.g.
[msnaged DLL]Imports System.Runtime. InteropServices
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Private str As String
Public Property HostStr()
Get
HostStr = str
End Get
Set(ByVal Value)
str = Value
End Set
End Property
Private Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream
Dim MyFormatter As New BinaryFormatter
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
Public Function Clone()
Dim siteUri As New Uri("http://www.contoso.com/")
Dim cloneuri As Uri
cloneuri = CloneMe(siteUri )
HostStr = cloneuri.Host
End Function
End Class

[VB6]
Private Sub Command1_Click( )
Dim o As New ClassLibrary4.C lass1
Dim str As String
o.Clone
MsgBox o.HostStr
End Sub

Did I misunderstand you meaning?
If you have any related question please feel free to let me know.

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.
--------------------
From: "Ben Hannon" <ha****@brodart .com>
References: <eQ************ *@TK2MSFTNGP10. phx.gbl> <eS************ **@tk2msftngp13 .phx.gbl>
<##************ **@TK2MSFTNGP10 .phx.gbl>
<sI************ **@cpmsftngxa06 .phx.gbl>Subject: Re: VB.NET COLLECTION VB6 COM
Date: Fri, 17 Oct 2003 15:01:04 -0400
Lines: 218
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eq************ **@TK2MSFTNGP12 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147794
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Peter,

Actually, it's not a VB6 object. The classes that will be
serialized/Cloned are written in VB.NET and compiled as a DLL with COM
Interop. All of the serialization is done internally in the DLL so that the.NET runtime is being used, not VB6 runtime and is only serializing the .NETclass (nothing passed from VB6). Serializing the object works perfectly,
the part that barfs is when I try to deserialize the memorystream that was
just serialized along with Deserializing a binary file. Deserialize errors:"Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutra l, PublicKeyToken= null." I added some more code in my DLL to
loop through the AppDomain.Curre ntDomain.GetAss emblies and msgbox the
assembly info to check if the assembly was loaded and it was, however when Itried
Path.GetDirect oryName(System. Reflection.Assb ly.GetEntryAsse mbly().Location )
to get the DLL's path, that errored with "Object reference not set to an
instance of an object" which tells me that the current loaded assembly it
not defaulted at that point. Looks like I may have to load the assembly a
second time before deserializing? All of this code however works when
compiled as a .NET Console App. My next thing I'm gonna try is copying the
DLL/TLB to my VB6 app and reference it to there, maybe that will fix the
problem. If you would like to see my code, I can post it.

Ben
"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:sI******* *******@cpmsftn gxa06.phx.gbl.. .
Hi Ben,

Based on my understanding, you want to pass a VB6 object to the CloneMe
method to be serialized.
I think it is not a proper method to do so.
Since when interoperation between VB and .NET, the Object passed from VBto
NET is an COM object.
The serialization implement between COM and .NET is different, that is to
say if you serialize a COM object
in .NET, the .NET framework will not know how to serialize the object.

In my test the error will occur at the line below.

MyFormatter.Ser ialize(myMemory Stream, Data)
Because .NET framework do not know how to serialize the Object Data.

This is my sample code, is that what you are doing in your code?
If you have any question, please feel free to let me know.

[VB6]
Private Sub Command1_Click( )
Dim so As New ClassLibrary3.C lass1
Text1.Text = "1000"
Dim obj As Object
obj = so.CloneMe(ByVa l Text1)
MsgBox obj.Text
End Sub

[ClassLibrary3.C lass1]
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
Imports System.Runtime. InteropServices
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream()

Dim MyFormatter As New BinaryFormatter ()
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "

&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
End Class
BTW
Are your VB.NET dll named as TartanCls?
If so, you may need to place it in the same directory as the VB6 Exe file
or you can use the command line below to register the VB.NET classlibrary.
regasm /codebase ClassLibrary3.d ll

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.
--------------------
>From: "Ben Hannon" <ha****@brodart .com>
>References: <eQ************ *@TK2MSFTNGP10. phx.gbl>

<eS************ **@tk2msftngp13 .phx.gbl>
>Subject: Re: VB.NET COLLECTION VB6 COM
>Date: Thu, 16 Oct 2003 11:59:55 -0400
>Lines: 243
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_ 0092_01C393DD.0 3CE8EF0"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <##************ **@TK2MSFTNGP10 .phx.gbl>
>Newsgroups: microsoft.publi c.dotnet.langua ges.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
>Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147338
>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
>
>I did a little more looking into this bug and discovered it is occurring

when I try
>to deserialize my Memory Stream:
>Public Function CloneMe(ByVal Data As Object) As Object
>Dim myMemoryStream As New System.IO.Memor yStream
>Dim MyFormatter As New BinaryFormatter
>Try
>MsgBox("Befo re Serialization. " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity)
>MyFormatter.Se rialize(myMemor yStream, Data)
>MsgBox("Afte r Serialization. " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "

&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>myMemoryStream .Seek(0, SeekOrigin.Begi n)
>MsgBox("Afte r Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " &

myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>***CloneMe = MyFormatter.Des erialize(myMemo ryStream)
>MsgBox("Afte r Deserialization . " & vbCrLf & vbCrLf & "Memory Stream

Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "

&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>myMemoryStream .Close()
>myMemoryStre am = Nothing
>Catch
>MsgBox("Erro r occurred in sub CloneMe." & vbCrLf & vbCrLf &

Err.Description , MsgBoxStyle.Cri tical)
>CloneMe = Nothing
>End Try
>End Function
>The red/asterisked line above is the line that generates this error.
>Ben Hannon
>"Ben Hannon" <ha****@brodart .com> wrote in message

news:eS******** ******@tk2msftn gp13.phx.gbl...
>> Actually, those links helped me decide to kill trying to pass the VBA
>> Collection since I can't serialize it. What I decided to do instead
is to
>> create a VB.NET collection with the ArrayList class and expose the

methods
>> needed for COM Interop. Everything works perfectly when running the

Class
>> as a Console App (clone works perfectly). However, when I compile it
asa >> DLL and try to use it in my VB6 app, when I try to clone an object I

get
the
>> error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
>> Culture=neutral , PublicKeyToken= null." Any ideas?
>>
>> Ben Hannon
>>
>> "Ben Hannon" <ha****@brodart .com> wrote in message
>> news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
>> > Hi,
>> >
>> > I'm writting a COM Class in VB.NET to be used in a VB6 project

(Tired of
>> > the VB6 hassles with cloning and serializing an object). All my
>> > classes I need cloneable/serializable are now in a VB.NET class that
>> exposes
>> > those objects to COM perfectly. However I ran into a problem

because some
>> > of these objects requires a Collection. When I compile this project

with
>> > the VB.NET Collection exposed for a property, I get a compile time

error
>> > that VB cann't find Type Library "Microsoft.Visu alBasic". I even

tried
>> > using VBA.CollectionC lass, but everytime I try to create a new
object in
>> > VB6, the object stays equal to nothing (Doesn't create).
>> >
>> > Ben Hannon
>> > Williamsport, PA
>> >
>> >
>>
>>
>



Nov 20 '05 #9
Peter,

This is exactly what I'm trying to do. The VB.NET DLL contains the
classes and Serialization code. I reference the DLL in VB6 and when I try
to execute the .clone method or .Load method (Loads settings from a
serialized file) I get the error that the assembly cannot be found when the
deserialize method is used. Like I said before, I looped through the
appdomain.curre ntdomain.getass emblies collection to see if the assembly was
loaded and it was. So for some odd reason, the deserialized method is not
finding it. Is there any way to force the deserialized method to use a
certain assembly?

Ben Hannon

"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:2d******** ******@cpmsftng xa06.phx.gbl...
Hi Ben,

If your project is somewhat large, you may post a simple sample to
demostrate what you want to do and reproduce the problem.
Based on my understanding, you want to call an method of an managed DLL,
and the method will do the clone in the DLL.
e.g.
[msnaged DLL]Imports System.Runtime. InteropServices
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Private str As String
Public Property HostStr()
Get
HostStr = str
End Get
Set(ByVal Value)
str = Value
End Set
End Property
Private Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream
Dim MyFormatter As New BinaryFormatter
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
Public Function Clone()
Dim siteUri As New Uri("http://www.contoso.com/")
Dim cloneuri As Uri
cloneuri = CloneMe(siteUri )
HostStr = cloneuri.Host
End Function
End Class

[VB6]
Private Sub Command1_Click( )
Dim o As New ClassLibrary4.C lass1
Dim str As String
o.Clone
MsgBox o.HostStr
End Sub

Did I misunderstand you meaning?
If you have any related question please feel free to let me know.

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.
--------------------
From: "Ben Hannon" <ha****@brodart .com>
References: <eQ************ *@TK2MSFTNGP10. phx.gbl> <eS************ **@tk2msftngp13 .phx.gbl>
<##************ **@TK2MSFTNGP10 .phx.gbl>
<sI************ **@cpmsftngxa06 .phx.gbl>
Subject: Re: VB.NET COLLECTION VB6 COM
Date: Fri, 17 Oct 2003 15:01:04 -0400
Lines: 218
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eq************ **@TK2MSFTNGP12 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147794
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Peter,

Actually, it's not a VB6 object. The classes that will be
serialized/Cloned are written in VB.NET and compiled as a DLL with COM
Interop. All of the serialization is done internally in the DLL so that

the
.NET runtime is being used, not VB6 runtime and is only serializing the

NET
class (nothing passed from VB6). Serializing the object works perfectly,
the part that barfs is when I try to deserialize the memorystream that was
just serialized along with Deserializing a binary file. Deserialize

errors:
"Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
Culture=neutra l, PublicKeyToken= null." I added some more code in my DLL toloop through the AppDomain.Curre ntDomain.GetAss emblies and msgbox the
assembly info to check if the assembly was loaded and it was, however when I
tried


Path.GetDirect oryName(System. Reflection.Assb ly.GetEntryAsse mbly().Location )
to get the DLL's path, that errored with "Object reference not set to an
instance of an object" which tells me that the current loaded assembly it
not defaulted at that point. Looks like I may have to load the assembly

asecond time before deserializing? All of this code however works when
compiled as a .NET Console App. My next thing I'm gonna try is copying theDLL/TLB to my VB6 app and reference it to there, maybe that will fix the
problem. If you would like to see my code, I can post it.

Ben
"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:sI******* *******@cpmsftn gxa06.phx.gbl.. .
Hi Ben,

Based on my understanding, you want to pass a VB6 object to the CloneMe
method to be serialized.
I think it is not a proper method to do so.
Since when interoperation between VB and .NET, the Object passed from VB
to
NET is an COM object.
The serialization implement between COM and .NET is different, that is
to say if you serialize a COM object
in .NET, the .NET framework will not know how to serialize the object.

In my test the error will occur at the line below.

MyFormatter.Ser ialize(myMemory Stream, Data)
Because .NET framework do not know how to serialize the Object Data.

This is my sample code, is that what you are doing in your code?
If you have any question, please feel free to let me know.

[VB6]
Private Sub Command1_Click( )
Dim so As New ClassLibrary3.C lass1
Text1.Text = "1000"
Dim obj As Object
obj = so.CloneMe(ByVa l Text1)
MsgBox obj.Text
End Sub

[ClassLibrary3.C lass1]
Imports System.Runtime. Serialization.F ormatters.Binar y
Imports System.IO
Imports System.Runtime. InteropServices
<ClassInterface (ClassInterface Type.AutoDual)> _
Public Class Class1
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.Memor yStream()

Dim MyFormatter As New BinaryFormatter ()
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity)
MyFormatter.Ser ialize(myMemory Stream, Data)
MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " & myMemoryStream. Position)
myMemoryStream. Seek(0, SeekOrigin.Begi n)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
CloneMe = MyFormatter.Des erialize(myMemo ryStream)
MsgBox("After Deserialization . " & vbCrLf & vbCrLf &
"Memory Stream Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream
Length: " & myMemoryStream. Length & vbCrLf & "Memory Stream Position: " & myMemoryStream. Position)
myMemoryStream. Close()
myMemoryStream = Nothing
Catch
MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
CloneMe = Nothing
End Try
End Function
End Class
BTW
Are your VB.NET dll named as TartanCls?
If so, you may need to place it in the same directory as the VB6 Exe file or you can use the command line below to register the VB.NET

classlibrary. regasm /codebase ClassLibrary3.d ll

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.
--------------------
>From: "Ben Hannon" <ha****@brodart .com>
>References: <eQ************ *@TK2MSFTNGP10. phx.gbl>
<eS************ **@tk2msftngp13 .phx.gbl>
>Subject: Re: VB.NET COLLECTION VB6 COM
>Date: Thu, 16 Oct 2003 11:59:55 -0400
>Lines: 243
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_ 0092_01C393DD.0 3CE8EF0"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <##************ **@TK2MSFTNGP10 .phx.gbl>
>Newsgroups: microsoft.publi c.dotnet.langua ges.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
>Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147338
>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
>
>I did a little more looking into this bug and discovered it is occurring when I try
>to deserialize my Memory Stream:
>Public Function CloneMe(ByVal Data As Object) As Object
>Dim myMemoryStream As New System.IO.Memor yStream
>Dim MyFormatter As New BinaryFormatter
>Try
>MsgBox("Befo re Serialization. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity)
>MyFormatter.Se rialize(myMemor yStream, Data)
>MsgBox("Afte r Serialization. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>myMemoryStream .Seek(0, SeekOrigin.Begi n)
>MsgBox("Afte r Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: "
& myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>***CloneMe = MyFormatter.Des erialize(myMemo ryStream)
>MsgBox("Afte r Deserialization . " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream. Capacity & vbCrLf & "Memory Stream Length: "
&
myMemoryStream. Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream. Position)
>myMemoryStream .Close()
>myMemoryStre am = Nothing
>Catch
>MsgBox("Erro r occurred in sub CloneMe." & vbCrLf & vbCrLf &
Err.Description , MsgBoxStyle.Cri tical)
>CloneMe = Nothing
>End Try
>End Function
>The red/asterisked line above is the line that generates this error.
>Ben Hannon
>"Ben Hannon" <ha****@brodart .com> wrote in message
news:eS******** ******@tk2msftn gp13.phx.gbl...
>> Actually, those links helped me decide to kill trying to pass the

VBA >> Collection since I can't serialize it. What I decided to do instead

is to
>> create a VB.NET collection with the ArrayList class and expose the
methods
>> needed for COM Interop. Everything works perfectly when running the
Class
>> as a Console App (clone works perfectly). However, when I compile it as
a
>> DLL and try to use it in my VB6 app, when I try to clone an object I

get
the
>> error "Cannot find the assembly TartanCls, Version=1.0.138 4.16492,
>> Culture=neutral , PublicKeyToken= null." Any ideas?
>>
>> Ben Hannon
>>
>> "Ben Hannon" <ha****@brodart .com> wrote in message
>> news:eQ******** *****@TK2MSFTNG P10.phx.gbl...
>> > Hi,
>> >
>> > I'm writting a COM Class in VB.NET to be used in a VB6 project
(Tired of
>> > the VB6 hassles with cloning and serializing an object). All my
>> > classes I need cloneable/serializable are now in a VB.NET class that >> exposes
>> > those objects to COM perfectly. However I ran into a problem

because some
>> > of these objects requires a Collection. When I compile this project with
>> > the VB.NET Collection exposed for a property, I get a compile time
error
>> > that VB cann't find Type Library "Microsoft.Visu alBasic". I even
tried
>> > using VBA.CollectionC lass, but everytime I try to create a new object in
>> > VB6, the object stays equal to nothing (Doesn't create).
>> >
>> > Ben Hannon
>> > Williamsport, PA
>> >
>> >
>>
>>
>


Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2200
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in the process), I looked up the STL code. Erase certainly does not delete the memory associated with the element. However, it appears that the destructor on the element is invoked. I wonder why it has to be this way. In my opinion, this renders...
5
2721
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use the appointment collection to populate the calendar control. The performance getting the XML data is fine, but loading the data into the collection is slow. My question/problem is should I be using the collection, a dataset, or something else to...
18
5735
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are not in chronological order. Is there a way to first sort the collection and put the dates in chronological order before creating the value list string? Or, how would I iterate over the collection pulling out the dates in chronological order? ...
11
18699
by: Pavils Jurjans | last post by:
Hello, There's some confusion about the purpose and difference between these handy classes... First, both of them are holding number of key - value pairs, right? Then, I see that there may be some difference in terms of data types allowed for keys and values, perhaps? I read the following in MSDN about "CollectionBase" class and
2
3169
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
6
4833
by: Michael D. Ober | last post by:
In VB 6, the loop iterator v in the following code must be a variant. dim v as variant dim c as new collection for each v in collection ... next v What is the general translation in VB 7.1 and VB 8 Beta 1? Also, is there an easy way to force "v" to be an early bound variable. In VB 6 this can be
3
2147
by: Matt Michael | last post by:
I have a listview control and a collection object right now that I'm trying to pass information to and from. Whenever I click on the checkbox, I want it to remove certain listview items and add them to the collection. Whenever I uncheck the checkbox, I want to add the items back into the listview from the collection, and remove them from the collection so I can do the process multiple times. The listview tag is being used as a key, so I...
10
2762
by: Chet Cromer | last post by:
I am creating a set of base classes and sub classes to use throughout a program I'm developing. The base class represents a generic "lookup table" from my database that contains lists of things like manufacturers, makes, modes, etc. of cars. I have created a generic "datacollection" class and a generic "dataobject" class to represent the table and the rows within that table as a collection of objects with generic properties for...
6
13395
by: Scott M. Lyon | last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I can update existing VB6 code to (for several specific functions) return a Hashtable from a .NET library. I've had very little luck processing the Hashtable itself in VB6 (I can add a reference to the project so it knows what a Hashtable is, but I'm not having much luck looping through all objects in the Hashtable), so I decided to try a different idea.
6
7202
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.