Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.NET COLLECTION VB6 COM

Ben Hannon
Guest
 
Posts: n/a
#1: Nov 20 '05
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.VisualBasic". I even tried
using VBA.CollectionClass, but everytime I try to create a new object in
VB6, the object stays equal to nothing (Doesn't create).

Ben Hannon
Williamsport, PA



Mattias Sj鐷ren
Guest
 
Posts: n/a
#2: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Ben

See if this helps

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



Mattias

--
Mattias Sj鐷ren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Peter Huang [MSFT]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.
--------------------[color=blue]
>From: "Ben Hannon" <hannon@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: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:146549
>X-Tomcat-NG: microsoft.public.dotnet.languages.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[/color]
exposes[color=blue]
>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.VisualBasic". I even tried
>using VBA.CollectionClass, but everytime I try to create a new object in
>VB6, the object stays equal to nothing (Doesn't create).
>
>Ben Hannon
>Williamsport, PA
>
>
>[/color]

Ben Hannon
Guest
 
Posts: n/a
#4: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.1384.16492,
Culture=neutral, PublicKeyToken=null." Any ideas?

Ben Hannon

"Ben Hannon" <hannon@brodart.com> wrote in message
news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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[/color]
exposes[color=blue]
> 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.VisualBasic". I even tried
> using VBA.CollectionClass, but everytime I try to create a new object in
> VB6, the object stays equal to nothing (Doesn't create).
>
> Ben Hannon
> Williamsport, PA
>
>[/color]


Ben Hannon
Guest
 
Posts: n/a
#5: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.1384.16492,
Culture=neutral, PublicKeyToken=null." Any ideas?

Ben Hannon

"Ben Hannon" <hannon@brodart.com> wrote in message
news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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[/color]
exposes[color=blue]
> 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.VisualBasic". I even tried
> using VBA.CollectionClass, but everytime I try to create a new object in
> VB6, the object stays equal to nothing (Doesn't create).
>
> Ben Hannon
> Williamsport, PA
>
>[/color]


Ben Hannon
Guest
 
Posts: n/a
#6: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.MemoryStream

Dim MyFormatter As New BinaryFormatter

Try

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

MyFormatter.Serialize(myMemoryStream, 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.Begin)

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

***CloneMe = MyFormatter.Deserialize(myMemoryStream)

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.Critical)

CloneMe = Nothing

End Try

End Function

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



Ben Hannon

"Ben Hannon" <hannon@brodart.com> wrote in message news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...[color=blue]
> 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.1384.16492,
> Culture=neutral, PublicKeyToken=null." Any ideas?
>
> Ben Hannon
>
> "Ben Hannon" <hannon@brodart.com> wrote in message
> news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...[color=green]
> > 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[/color]
> exposes[color=green]
> > 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.VisualBasic". I even tried
> > using VBA.CollectionClass, but everytime I try to create a new object in
> > VB6, the object stays equal to nothing (Doesn't create).
> >
> > Ben Hannon
> > Williamsport, PA
> >
> >[/color]
>
>[/color]
Peter Huang [MSFT]
Guest
 
Posts: n/a
#7: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.Serialize(myMemoryStream, 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.Class1
Text1.Text = "1000"
Dim obj As Object
obj = so.CloneMe(ByVal Text1)
MsgBox obj.Text
End Sub

[ClassLibrary3.Class1]
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class Class1
Public Function CloneMe(ByVal Data As Object) As Object
Dim myMemoryStream As New System.IO.MemoryStream()

Dim MyFormatter As New BinaryFormatter()
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream.Capacity)
MyFormatter.Serialize(myMemoryStream, 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.Begin)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream.Position)
CloneMe = MyFormatter.Deserialize(myMemoryStream)
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.Critical)
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.dll



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.

--------------------[color=blue]
>From: "Ben Hannon" <hannon@brodart.com>
>References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
<eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>[color=blue]
>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.03CE8EF0"
>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: <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147338
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
>I did a little more looking into this bug and discovered it is occurring[/color]
when I try[color=blue]
>to deserialize my Memory Stream:
>Public Function CloneMe(ByVal Data As Object) As Object
>Dim myMemoryStream As New System.IO.MemoryStream
>Dim MyFormatter As New BinaryFormatter
>Try
>MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
Capacity: " & myMemoryStream.Capacity)[color=blue]
>MyFormatter.Serialize(myMemoryStream, Data)
>MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream.Position)[color=blue]
>myMemoryStream.Seek(0, SeekOrigin.Begin)
>MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " &[/color]
myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream.Position)[color=blue]
>***CloneMe = MyFormatter.Deserialize(myMemoryStream)
>MsgBox("After Deserialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream.Position)[color=blue]
>myMemoryStream.Close()
>myMemoryStream = Nothing
>Catch
>MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &[/color]
Err.Description, MsgBoxStyle.Critical)[color=blue]
>CloneMe = Nothing
>End Try
>End Function
>The red/asterisked line above is the line that generates this error.
>Ben Hannon
>"Ben Hannon" <hannon@brodart.com> wrote in message[/color]
news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...[color=blue][color=green]
>> 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[/color][/color]
to[color=blue][color=green]
>> create a VB.NET collection with the ArrayList class and expose the[/color][/color]
methods[color=blue][color=green]
>> needed for COM Interop. Everything works perfectly when running the[/color][/color]
Class[color=blue][color=green]
>> 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[/color][/color]
the[color=blue][color=green]
>> error "Cannot find the assembly TartanCls, Version=1.0.1384.16492,
>> Culture=neutral, PublicKeyToken=null." Any ideas?
>>
>> Ben Hannon
>>
>> "Ben Hannon" <hannon@brodart.com> wrote in message
>> news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...[color=darkred]
>> > Hi,
>> >
>> > I'm writting a COM Class in VB.NET to be used in a VB6 project[/color][/color][/color]
(Tired of[color=blue][color=green][color=darkred]
>> > the VB6 hassles with cloning and serializing an object). All my
>> > classes I need cloneable/serializable are now in a VB.NET class that[/color]
>> exposes[color=darkred]
>> > those objects to COM perfectly. However I ran into a problem because[/color][/color][/color]
some[color=blue][color=green][color=darkred]
>> > of these objects requires a Collection. When I compile this project[/color][/color][/color]
with[color=blue][color=green][color=darkred]
>> > the VB.NET Collection exposed for a property, I get a compile time[/color][/color][/color]
error[color=blue][color=green][color=darkred]
>> > that VB cann't find Type Library "Microsoft.VisualBasic". I even[/color][/color][/color]
tried[color=blue][color=green][color=darkred]
>> > using VBA.CollectionClass, but everytime I try to create a new object[/color][/color][/color]
in[color=blue][color=green][color=darkred]
>> > VB6, the object stays equal to nothing (Doesn't create).
>> >
>> > Ben Hannon
>> > Williamsport, PA
>> >
>> >[/color]
>>
>>[/color]
>[/color]

Ben Hannon
Guest
 
Posts: n/a
#8: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.1384.16492,
Culture=neutral, PublicKeyToken=null." I added some more code in my DLL to
loop through the AppDomain.CurrentDomain.GetAssemblies and msgbox the
assembly info to check if the assembly was loaded and it was, however when I
tried
Path.GetDirectoryName(System.Reflection.Assbly.Get EntryAssembly().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-phuang@online.microsoft.com> wrote in message
news:sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl...[color=blue]
> 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[/color]
to[color=blue]
> 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.Serialize(myMemoryStream, 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.Class1
> Text1.Text = "1000"
> Dim obj As Object
> obj = so.CloneMe(ByVal Text1)
> MsgBox obj.Text
> End Sub
>
> [ClassLibrary3.Class1]
> Imports System.Runtime.Serialization.Formatters.Binary
> Imports System.IO
> Imports System.Runtime.InteropServices
> <ClassInterface(ClassInterfaceType.AutoDual)> _
> Public Class Class1
> Public Function CloneMe(ByVal Data As Object) As Object
> Dim myMemoryStream As New System.IO.MemoryStream()
>
> Dim MyFormatter As New BinaryFormatter()
> Try
> MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
> Stream Capacity: " & myMemoryStream.Capacity)
> MyFormatter.Serialize(myMemoryStream, 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.Begin)
> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
&[color=blue]
> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> myMemoryStream.Position)
> CloneMe = MyFormatter.Deserialize(myMemoryStream)
> 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.Critical)
> 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.dll
>
>
>
> 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.
>
> --------------------[color=green]
> >From: "Ben Hannon" <hannon@brodart.com>
> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
> <eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>[color=green]
> >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.03CE8EF0"
> >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: <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
> >Newsgroups: microsoft.public.dotnet.languages.vb
> >NNTP-Posting-Host: 12.29.184.66
> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147338
> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb
> >
> >I did a little more looking into this bug and discovered it is occurring[/color]
> when I try[color=green]
> >to deserialize my Memory Stream:
> >Public Function CloneMe(ByVal Data As Object) As Object
> >Dim myMemoryStream As New System.IO.MemoryStream
> >Dim MyFormatter As New BinaryFormatter
> >Try
> >MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
> Capacity: " & myMemoryStream.Capacity)[color=green]
> >MyFormatter.Serialize(myMemoryStream, Data)
> >MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
&[color=blue]
> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> myMemoryStream.Position)[color=green]
> >myMemoryStream.Seek(0, SeekOrigin.Begin)
> >MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " &[/color]
> myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> myMemoryStream.Position)[color=green]
> >***CloneMe = MyFormatter.Deserialize(myMemoryStream)
> >MsgBox("After Deserialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
&[color=blue]
> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> myMemoryStream.Position)[color=green]
> >myMemoryStream.Close()
> >myMemoryStream = Nothing
> >Catch
> >MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &[/color]
> Err.Description, MsgBoxStyle.Critical)[color=green]
> >CloneMe = Nothing
> >End Try
> >End Function
> >The red/asterisked line above is the line that generates this error.
> >Ben Hannon
> >"Ben Hannon" <hannon@brodart.com> wrote in message[/color]
> news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...[color=green][color=darkred]
> >> 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[/color][/color]
> to[color=green][color=darkred]
> >> create a VB.NET collection with the ArrayList class and expose the[/color][/color]
> methods[color=green][color=darkred]
> >> needed for COM Interop. Everything works perfectly when running the[/color][/color]
> Class[color=green][color=darkred]
> >> as a Console App (clone works perfectly). However, when I compile it as[/color][/color][/color]
a[color=blue][color=green][color=darkred]
> >> DLL and try to use it in my VB6 app, when I try to clone an object I[/color][/color][/color]
get[color=blue]
> the[color=green][color=darkred]
> >> error "Cannot find the assembly TartanCls, Version=1.0.1384.16492,
> >> Culture=neutral, PublicKeyToken=null." Any ideas?
> >>
> >> Ben Hannon
> >>
> >> "Ben Hannon" <hannon@brodart.com> wrote in message
> >> news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...
> >> > Hi,
> >> >
> >> > I'm writting a COM Class in VB.NET to be used in a VB6 project[/color][/color]
> (Tired of[color=green][color=darkred]
> >> > 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[/color][/color]
> some[color=green][color=darkred]
> >> > of these objects requires a Collection. When I compile this project[/color][/color]
> with[color=green][color=darkred]
> >> > the VB.NET Collection exposed for a property, I get a compile time[/color][/color]
> error[color=green][color=darkred]
> >> > that VB cann't find Type Library "Microsoft.VisualBasic". I even[/color][/color]
> tried[color=green][color=darkred]
> >> > using VBA.CollectionClass, but everytime I try to create a new object[/color][/color]
> in[color=green][color=darkred]
> >> > VB6, the object stays equal to nothing (Doesn't create).
> >> >
> >> > Ben Hannon
> >> > Williamsport, PA
> >> >
> >> >
> >>
> >>[/color]
> >[/color]
>[/color]


Peter Huang [MSFT]
Guest
 
Posts: n/a
#9: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.Formatters.Binary
Imports System.IO
<ClassInterface(ClassInterfaceType.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.MemoryStream
Dim MyFormatter As New BinaryFormatter
Try
MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
Stream Capacity: " & myMemoryStream.Capacity)
MyFormatter.Serialize(myMemoryStream, 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.Begin)
MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
myMemoryStream.Position)
CloneMe = MyFormatter.Deserialize(myMemoryStream)
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.Critical)
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.Class1
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.
--------------------[color=blue]
>From: "Ben Hannon" <hannon@brodart.com>
>References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
<eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>
<##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
<sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl>[color=blue]
>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: <eqWAFEOlDHA.2216@TK2MSFTNGP12.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147794
>X-Tomcat-NG: microsoft.public.dotnet.languages.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[/color]
the[color=blue]
>.NET runtime is being used, not VB6 runtime and is only serializing the[/color]
.NET[color=blue]
>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[/color]
errors:[color=blue]
>"Cannot find the assembly TartanCls, Version=1.0.1384.16492,
>Culture=neutral, PublicKeyToken=null." I added some more code in my DLL to
>loop through the AppDomain.CurrentDomain.GetAssemblies and msgbox the
>assembly info to check if the assembly was loaded and it was, however when[/color]
I[color=blue]
>tried
>Path.GetDirectoryName(System.Reflection.Assbly.Ge tEntryAssembly().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-phuang@online.microsoft.com> wrote in message
>news:sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl...[color=green]
>> 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[/color]
>to[color=green]
>> 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.Serialize(myMemoryStream, 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.Class1
>> Text1.Text = "1000"
>> Dim obj As Object
>> obj = so.CloneMe(ByVal Text1)
>> MsgBox obj.Text
>> End Sub
>>
>> [ClassLibrary3.Class1]
>> Imports System.Runtime.Serialization.Formatters.Binary
>> Imports System.IO
>> Imports System.Runtime.InteropServices
>> <ClassInterface(ClassInterfaceType.AutoDual)> _
>> Public Class Class1
>> Public Function CloneMe(ByVal Data As Object) As Object
>> Dim myMemoryStream As New System.IO.MemoryStream()
>>
>> Dim MyFormatter As New BinaryFormatter()
>> Try
>> MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
>> Stream Capacity: " & myMemoryStream.Capacity)
>> MyFormatter.Serialize(myMemoryStream, 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.Begin)
>> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
>> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
>&[color=green]
>> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> myMemoryStream.Position)
>> CloneMe = MyFormatter.Deserialize(myMemoryStream)
>> 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.Critical)
>> 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[/color][/color]
classlibrary.[color=blue][color=green]
>> regasm /codebase ClassLibrary3.dll
>>
>>
>>
>> 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[/color][/color]
rights.[color=blue][color=green]
>>
>> --------------------[color=darkred]
>> >From: "Ben Hannon" <hannon@brodart.com>
>> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
>> <eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>[color=darkred]
>> >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.03CE8EF0"
>> >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: <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
>> >Newsgroups: microsoft.public.dotnet.languages.vb
>> >NNTP-Posting-Host: 12.29.184.66
>> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147338
>> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>> >
>> >I did a little more looking into this bug and discovered it is occurring[/color]
>> when I try[color=darkred]
>> >to deserialize my Memory Stream:
>> >Public Function CloneMe(ByVal Data As Object) As Object
>> >Dim myMemoryStream As New System.IO.MemoryStream
>> >Dim MyFormatter As New BinaryFormatter
>> >Try
>> >MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
>> Capacity: " & myMemoryStream.Capacity)[color=darkred]
>> >MyFormatter.Serialize(myMemoryStream, Data)
>> >MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
>> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
>&[color=green]
>> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> myMemoryStream.Position)[color=darkred]
>> >myMemoryStream.Seek(0, SeekOrigin.Begin)
>> >MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: " &[/color]
>> myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
>> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> myMemoryStream.Position)[color=darkred]
>> >***CloneMe = MyFormatter.Deserialize(myMemoryStream)
>> >MsgBox("After Deserialization. " & vbCrLf & vbCrLf & "Memory Stream[/color]
>> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
>&[color=green]
>> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> myMemoryStream.Position)[color=darkred]
>> >myMemoryStream.Close()
>> >myMemoryStream = Nothing
>> >Catch
>> >MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &[/color]
>> Err.Description, MsgBoxStyle.Critical)[color=darkred]
>> >CloneMe = Nothing
>> >End Try
>> >End Function
>> >The red/asterisked line above is the line that generates this error.
>> >Ben Hannon
>> >"Ben Hannon" <hannon@brodart.com> wrote in message[/color]
>> news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...[color=darkred]
>> >> 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[/color][/color][/color]
is[color=blue][color=green]
>> to[color=darkred]
>> >> create a VB.NET collection with the ArrayList class and expose the[/color]
>> methods[color=darkred]
>> >> needed for COM Interop. Everything works perfectly when running the[/color]
>> Class[color=darkred]
>> >> as a Console App (clone works perfectly). However, when I compile it[/color][/color][/color]
as[color=blue]
>a[color=green][color=darkred]
>> >> DLL and try to use it in my VB6 app, when I try to clone an object I[/color][/color]
>get[color=green]
>> the[color=darkred]
>> >> error "Cannot find the assembly TartanCls, Version=1.0.1384.16492,
>> >> Culture=neutral, PublicKeyToken=null." Any ideas?
>> >>
>> >> Ben Hannon
>> >>
>> >> "Ben Hannon" <hannon@brodart.com> wrote in message
>> >> news:eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl...
>> >> > Hi,
>> >> >
>> >> > I'm writting a COM Class in VB.NET to be used in a VB6 project[/color]
>> (Tired of[color=darkred]
>> >> > 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[/color][/color][/color]
because[color=blue][color=green]
>> some[color=darkred]
>> >> > of these objects requires a Collection. When I compile this project[/color]
>> with[color=darkred]
>> >> > the VB.NET Collection exposed for a property, I get a compile time[/color]
>> error[color=darkred]
>> >> > that VB cann't find Type Library "Microsoft.VisualBasic". I even[/color]
>> tried[color=darkred]
>> >> > using VBA.CollectionClass, but everytime I try to create a new[/color][/color][/color]
object[color=blue][color=green]
>> in[color=darkred]
>> >> > VB6, the object stays equal to nothing (Doesn't create).
>> >> >
>> >> > Ben Hannon
>> >> > Williamsport, PA
>> >> >
>> >> >
>> >>
>> >>
>> >[/color]
>>[/color]
>
>
>[/color]

Ben Hannon
Guest
 
Posts: n/a
#10: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


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.currentdomain.getassemblies 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-phuang@online.microsoft.com> wrote in message
news:2duTFStlDHA.2452@cpmsftngxa06.phx.gbl...[color=blue]
> 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.Formatters.Binary
> Imports System.IO
> <ClassInterface(ClassInterfaceType.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.MemoryStream
> Dim MyFormatter As New BinaryFormatter
> Try
> MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
> Stream Capacity: " & myMemoryStream.Capacity)
> MyFormatter.Serialize(myMemoryStream, 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.Begin)
> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
&[color=blue]
> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> myMemoryStream.Position)
> CloneMe = MyFormatter.Deserialize(myMemoryStream)
> 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.Critical)
> 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.Class1
> 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.
> --------------------[color=green]
> >From: "Ben Hannon" <hannon@brodart.com>
> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
> <eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>
> <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
> <sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl>[color=green]
> >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: <eqWAFEOlDHA.2216@TK2MSFTNGP12.phx.gbl>
> >Newsgroups: microsoft.public.dotnet.languages.vb
> >NNTP-Posting-Host: 12.29.184.66
> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147794
> >X-Tomcat-NG: microsoft.public.dotnet.languages.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[/color]
> the[color=green]
> >.NET runtime is being used, not VB6 runtime and is only serializing the[/color]
> NET[color=green]
> >class (nothing passed from VB6). Serializing the object works perfectly,
> >the part that barfs is when I try to deserialize the memorystream that[/color][/color]
was[color=blue][color=green]
> >just serialized along with Deserializing a binary file. Deserialize[/color]
> errors:[color=green]
> >"Cannot find the assembly TartanCls, Version=1.0.1384.16492,
> >Culture=neutral, PublicKeyToken=null." I added some more code in my DLL[/color][/color]
to[color=blue][color=green]
> >loop through the AppDomain.CurrentDomain.GetAssemblies and msgbox the
> >assembly info to check if the assembly was loaded and it was, however[/color][/color]
when[color=blue]
> I[color=green]
> >tried[/color]
>
>Path.GetDirectoryName(System.Reflection.Assbly.Ge tEntryAssembly().Location)[color=green]
> >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[/color][/color]
a[color=blue][color=green]
> >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[/color][/color]
the[color=blue][color=green]
> >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-phuang@online.microsoft.com> wrote in message
> >news:sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl...[color=darkred]
> >> 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[/color][/color][/color]
VB[color=blue][color=green]
> >to[color=darkred]
> >> NET is an COM object.
> >> The serialization implement between COM and .NET is different, that is[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> >> 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.Serialize(myMemoryStream, 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.Class1
> >> Text1.Text = "1000"
> >> Dim obj As Object
> >> obj = so.CloneMe(ByVal Text1)
> >> MsgBox obj.Text
> >> End Sub
> >>
> >> [ClassLibrary3.Class1]
> >> Imports System.Runtime.Serialization.Formatters.Binary
> >> Imports System.IO
> >> Imports System.Runtime.InteropServices
> >> <ClassInterface(ClassInterfaceType.AutoDual)> _
> >> Public Class Class1
> >> Public Function CloneMe(ByVal Data As Object) As Object
> >> Dim myMemoryStream As New System.IO.MemoryStream()
> >>
> >> Dim MyFormatter As New BinaryFormatter()
> >> Try
> >> MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
> >> Stream Capacity: " & myMemoryStream.Capacity)
> >> MyFormatter.Serialize(myMemoryStream, Data)
> >> MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
> >> Stream Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream
> >> Length: " & myMemoryStream.Length & vbCrLf & "Memory Stream Position: "[/color][/color][/color]
&[color=blue][color=green][color=darkred]
> >> myMemoryStream.Position)
> >> myMemoryStream.Seek(0, SeekOrigin.Begin)
> >> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length:[/color][/color][/color]
"[color=blue][color=green]
> >&[color=darkred]
> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> >> myMemoryStream.Position)
> >> CloneMe = MyFormatter.Deserialize(myMemoryStream)
> >> MsgBox("After Deserialization. " & vbCrLf & vbCrLf &[/color][/color][/color]
"Memory[color=blue][color=green][color=darkred]
> >> Stream Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream
> >> Length: " & myMemoryStream.Length & vbCrLf & "Memory Stream Position: "[/color][/color][/color]
&[color=blue][color=green][color=darkred]
> >> myMemoryStream.Position)
> >> myMemoryStream.Close()
> >> myMemoryStream = Nothing
> >> Catch
> >> MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
> >> Err.Description, MsgBoxStyle.Critical)
> >> 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[/color][/color][/color]
file[color=blue][color=green][color=darkred]
> >> or you can use the command line below to register the VB.NET[/color][/color]
> classlibrary.[color=green][color=darkred]
> >> regasm /codebase ClassLibrary3.dll
> >>
> >>
> >>
> >> 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[/color][/color]
> rights.[color=green][color=darkred]
> >>
> >> --------------------
> >> >From: "Ben Hannon" <hannon@brodart.com>
> >> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>
> >> <eSosGI$kDHA.1656@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.03CE8EF0"
> >> >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: <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
> >> >Newsgroups: microsoft.public.dotnet.languages.vb
> >> >NNTP-Posting-Host: 12.29.184.66
> >> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
> >> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147338
> >> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb
> >> >
> >> >I did a little more looking into this bug and discovered it is[/color][/color][/color]
occurring[color=blue][color=green][color=darkred]
> >> when I try
> >> >to deserialize my Memory Stream:
> >> >Public Function CloneMe(ByVal Data As Object) As Object
> >> >Dim myMemoryStream As New System.IO.MemoryStream
> >> >Dim MyFormatter As New BinaryFormatter
> >> >Try
> >> >MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream
> >> Capacity: " & myMemoryStream.Capacity)
> >> >MyFormatter.Serialize(myMemoryStream, Data)
> >> >MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream
> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length:[/color][/color][/color]
"[color=blue][color=green]
> >&[color=darkred]
> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> >> myMemoryStream.Position)
> >> >myMemoryStream.Seek(0, SeekOrigin.Begin)
> >> >MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: "[/color][/color][/color]
&[color=blue][color=green][color=darkred]
> >> myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> >> myMemoryStream.Position)
> >> >***CloneMe = MyFormatter.Deserialize(myMemoryStream)
> >> >MsgBox("After Deserialization. " & vbCrLf & vbCrLf & "Memory Stream
> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length:[/color][/color][/color]
"[color=blue][color=green]
> >&[color=darkred]
> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
> >> myMemoryStream.Position)
> >> >myMemoryStream.Close()
> >> >myMemoryStream = Nothing
> >> >Catch
> >> >MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
> >> Err.Description, MsgBoxStyle.Critical)
> >> >CloneMe = Nothing
> >> >End Try
> >> >End Function
> >> >The red/asterisked line above is the line that generates this error.
> >> >Ben Hannon
> >> >"Ben Hannon" <hannon@brodart.com> wrote in message
> >> news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...
> >> >> Actually, those links helped me decide to kill trying to pass the[/color][/color][/color]
VBA[color=blue][color=green][color=darkred]
> >> >> Collection since I can't serialize it. What I decided to do instead[/color][/color]
> is[color=green][color=darkred]
> >> 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[/color][/color]
> as[color=green]
> >a[color=darkred]
> >> >> DLL and try to use it in my VB6 app, when I try to clone an object I[/color]
> >get[color=darkred]
> >> the
> >> >> error "Cannot find the assembly TartanCls, Version=1.0.1384.16492,
> >> >> Culture=neutral, PublicKeyToken=null." Any ideas?
> >> >>
> >> >> Ben Hannon
> >> >>
> >> >> "Ben Hannon" <hannon@brodart.com> wrote in message
> >> >> news:eQExldlkDHA.964@TK2MSFTNGP10.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[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> >> >> exposes
> >> >> > those objects to COM perfectly. However I ran into a problem[/color][/color]
> because[color=green][color=darkred]
> >> some
> >> >> > of these objects requires a Collection. When I compile this[/color][/color][/color]
project[color=blue][color=green][color=darkred]
> >> with
> >> >> > the VB.NET Collection exposed for a property, I get a compile time
> >> error
> >> >> > that VB cann't find Type Library "Microsoft.VisualBasic". I even
> >> tried
> >> >> > using VBA.CollectionClass, but everytime I try to create a new[/color][/color]
> object[color=green][color=darkred]
> >> in
> >> >> > VB6, the object stays equal to nothing (Doesn't create).
> >> >> >
> >> >> > Ben Hannon
> >> >> > Williamsport, PA
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >
> >>[/color]
> >
> >
> >[/color]
>[/color]


Peter Huang [MSFT]
Guest
 
Posts: n/a
#11: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Hi Ben,

Can you post a sample that will reproduce the problem, so that I can
reproduce the problem on my machine? I will appreciate your efforts, or you
can email to me as an attachment.
You can email to my email with the "online" removed.

The code I post in my last post works on my machine, is that what you want
to do?
That is why I hope you can post your code, so that I can troubleshoot the
problem.

From your code, you use the serialize and deserialize method of the
instance of BinaryFormatter.
That is to say, the two methods will use the mscorlib.dll in your words.

And you can load an assembly and invoke its methods in the runtime. That is
to say , you can use the another assembly's method[e.g. deserialize] in
the runtime. But it is not recommended to serialize a object using one
assembly and deserialized the object using another assembly.
Here is a sample about call a loaded assembly in the runtime.

[ConsoleApp.exe]
Imports System.Reflection
Module Module1
Sub Main()
Dim SampleAssembly As [Assembly]
SampleAssembly =
[Assembly].LoadFrom("E:\TestNewGroup\VB.NET\ClassLibrary5\bi n\ClassLibrary5.
dll")
Dim t As Type
t = SampleAssembly.GetType("ClassLibrary5.HelloService Class")
Dim obj As Object
obj = Activator.CreateInstance(t)
Console.WriteLine(obj.HelloMethod("helo"))
End Sub
End Module

[ClassLibrary5.dll]
Imports System
Public Class HelloServiceClass
Inherits MarshalByRefObject
Private str As String
Public Sub New()
Console.WriteLine("Constructor")
End Sub
Public Property ObjFlag()
Get
ObjFlag = str
End Get
Set(ByVal Value)
str = ObjFlag
End Set
End Property
Public Function HelloMethod(ByVal name As String) As String
Return "Hi there " + name + "."
End Function
End Class

I look forward to hearing from you.

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.
--------------------[color=blue]
>From: "Ben Hannon" <hannon@brodart.com>
>References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
<eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>
<##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
<sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl>
<eqWAFEOlDHA.2216@TK2MSFTNGP12.phx.gbl>
<2duTFStlDHA.2452@cpmsftngxa06.phx.gbl>[color=blue]
>Subject: Re: VB.NET COLLECTION VB6 COM
>Date: Mon, 20 Oct 2003 09:58:47 -0400
>Lines: 363
>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: <#PSsJJxlDHA.1884@TK2MSFTNGP09.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 12.29.184.66
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148390
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
>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.currentdomain.getassemblies 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-phuang@online.microsoft.com> wrote in message
>news:2duTFStlDHA.2452@cpmsftngxa06.phx.gbl...[color=green]
>> 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.Formatters.Binary
>> Imports System.IO
>> <ClassInterface(ClassInterfaceType.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.MemoryStream
>> Dim MyFormatter As New BinaryFormatter
>> Try
>> MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory
>> Stream Capacity: " & myMemoryStream.Capacity)
>> MyFormatter.Serialize(myMemoryStream, 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.Begin)
>> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
>> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: "[/color]
>&[color=green]
>> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> myMemoryStream.Position)
>> CloneMe = MyFormatter.Deserialize(myMemoryStream)
>> 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.Critical)
>> 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.Class1
>> 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[/color][/color]
rights.[color=blue][color=green]
>> --------------------[color=darkred]
>> >From: "Ben Hannon" <hannon@brodart.com>
>> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
>> <eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>
>> <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
>> <sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl>[color=darkred]
>> >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: <eqWAFEOlDHA.2216@TK2MSFTNGP12.phx.gbl>
>> >Newsgroups: microsoft.public.dotnet.languages.vb
>> >NNTP-Posting-Host: 12.29.184.66
>> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
>> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147794
>> >X-Tomcat-NG: microsoft.public.dotnet.languages.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[/color]
>> the[color=darkred]
>> >.NET runtime is being used, not VB6 runtime and is only serializing the[/color]
>> NET[color=darkred]
>> >class (nothing passed from VB6). Serializing the object works[/color][/color][/color]
perfectly,[color=blue][color=green][color=darkred]
>> >the part that barfs is when I try to deserialize the memorystream that[/color][/color]
>was[color=green][color=darkred]
>> >just serialized along with Deserializing a binary file. Deserialize[/color]
>> errors:[color=darkred]
>> >"Cannot find the assembly TartanCls, Version=1.0.1384.16492,
>> >Culture=neutral, PublicKeyToken=null." I added some more code in my DLL[/color][/color]
>to[color=green][color=darkred]
>> >loop through the AppDomain.CurrentDomain.GetAssemblies and msgbox the
>> >assembly info to check if the assembly was loaded and it was, however[/color][/color]
>when[color=green]
>> I[color=darkred]
>> >tried[/color]
>>
>>Path.GetDirectoryName(System.Reflection.Assbly.G etEntryAssembly().Location[/color][/color]
)[color=blue][color=green][color=darkred]
>> >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[/color][/color][/color]
it[color=blue][color=green][color=darkred]
>> >not defaulted at that point. Looks like I may have to load the assembly[/color][/color]
>a[color=green][color=darkred]
>> >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[/color][/color]
>the[color=green][color=darkred]
>> >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-phuang@online.microsoft.com> wrote in message
>> >news:sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl...
>> >> Hi Ben,
>> >>
>> >> Based on my understanding, you want to pass a VB6 object to the[/color][/color][/color]
CloneMe[color=blue][color=green][color=darkred]
>> >> 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[/color][/color]
>VB[color=green][color=darkred]
>> >to
>> >> NET is an COM object.
>> >> The serialization implement between COM and .NET is different, that is[/color][/color]
>to[color=green][color=darkred]
>> >> 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.Serialize(myMemoryStream, 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.Class1
>> >> Text1.Text = "1000"
>> >> Dim obj As Object
>> >> obj = so.CloneMe(ByVal Text1)
>> >> MsgBox obj.Text
>> >> End Sub
>> >>
>> >> [ClassLibrary3.Class1]
>> >> Imports System.Runtime.Serialization.Formatters.Binary
>> >> Imports System.IO
>> >> Imports System.Runtime.InteropServices
>> >> <ClassInterface(ClassInterfaceType.AutoDual)> _
>> >> Public Class Class1
>> >> Public Function CloneMe(ByVal Data As Object) As Object
>> >> Dim myMemoryStream As New System.IO.MemoryStream()
>> >>
>> >> Dim MyFormatter As New BinaryFormatter()
>> >> Try
>> >> MsgBox("Before Serialization. " & vbCrLf & vbCrLf &[/color][/color][/color]
"Memory[color=blue][color=green][color=darkred]
>> >> Stream Capacity: " & myMemoryStream.Capacity)
>> >> MyFormatter.Serialize(myMemoryStream, Data)
>> >> MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory
>> >> Stream Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream
>> >> Length: " & myMemoryStream.Length & vbCrLf & "Memory Stream Position:[/color][/color][/color]
"[color=blue]
>&[color=green][color=darkred]
>> >> myMemoryStream.Position)
>> >> myMemoryStream.Seek(0, SeekOrigin.Begin)
>> >> MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream
>> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream[/color][/color][/color]
Length:[color=blue]
>"[color=green][color=darkred]
>> >&
>> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> >> myMemoryStream.Position)
>> >> CloneMe = MyFormatter.Deserialize(myMemoryStream)
>> >> MsgBox("After Deserialization. " & vbCrLf & vbCrLf &[/color][/color]
>"Memory[color=green][color=darkred]
>> >> Stream Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream
>> >> Length: " & myMemoryStream.Length & vbCrLf & "Memory Stream Position:[/color][/color][/color]
"[color=blue]
>&[color=green][color=darkred]
>> >> myMemoryStream.Position)
>> >> myMemoryStream.Close()
>> >> myMemoryStream = Nothing
>> >> Catch
>> >> MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf[/color][/color][/color]
&[color=blue][color=green][color=darkred]
>> >> Err.Description, MsgBoxStyle.Critical)
>> >> 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[/color][/color]
>file[color=green][color=darkred]
>> >> or you can use the command line below to register the VB.NET[/color]
>> classlibrary.[color=darkred]
>> >> regasm /codebase ClassLibrary3.dll
>> >>
>> >>
>> >>
>> >> 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[/color]
>> rights.[color=darkred]
>> >>
>> >> --------------------
>> >> >From: "Ben Hannon" <hannon@brodart.com>
>> >> >References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>
>> >> <eSosGI$kDHA.1656@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.03CE8EF0"
>> >> >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: <##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
>> >> >Newsgroups: microsoft.public.dotnet.languages.vb
>> >> >NNTP-Posting-Host: 12.29.184.66
>> >> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>> >> >Xref: cpmsftngxa06.phx.gbl[/color][/color][/color]
microsoft.public.dotnet.languages.vb:147338[color=blue][color=green][color=darkred]
>> >> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>> >> >
>> >> >I did a little more looking into this bug and discovered it is[/color][/color]
>occurring[color=green][color=darkred]
>> >> when I try
>> >> >to deserialize my Memory Stream:
>> >> >Public Function CloneMe(ByVal Data As Object) As Object
>> >> >Dim myMemoryStream As New System.IO.MemoryStream
>> >> >Dim MyFormatter As New BinaryFormatter
>> >> >Try
>> >> >MsgBox("Before Serialization. " & vbCrLf & vbCrLf & "Memory Stream
>> >> Capacity: " & myMemoryStream.Capacity)
>> >> >MyFormatter.Serialize(myMemoryStream, Data)
>> >> >MsgBox("After Serialization. " & vbCrLf & vbCrLf & "Memory Stream
>> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream[/color][/color][/color]
Length:[color=blue]
>"[color=green][color=darkred]
>> >&
>> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> >> myMemoryStream.Position)
>> >> >myMemoryStream.Seek(0, SeekOrigin.Begin)
>> >> >MsgBox("After Reset. " & vbCrLf & vbCrLf & "Memory Stream Capacity: "[/color][/color]
>&[color=green][color=darkred]
>> >> myMemoryStream.Capacity & vbCrLf & "Memory Stream Length: " &
>> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> >> myMemoryStream.Position)
>> >> >***CloneMe = MyFormatter.Deserialize(myMemoryStream)
>> >> >MsgBox("After Deserialization. " & vbCrLf & vbCrLf & "Memory Stream
>> >> Capacity: " & myMemoryStream.Capacity & vbCrLf & "Memory Stream[/color][/color][/color]
Length:[color=blue]
>"[color=green][color=darkred]
>> >&
>> >> myMemoryStream.Length & vbCrLf & "Memory Stream Position: " &
>> >> myMemoryStream.Position)
>> >> >myMemoryStream.Close()
>> >> >myMemoryStream = Nothing
>> >> >Catch
>> >> >MsgBox("Error occurred in sub CloneMe." & vbCrLf & vbCrLf &
>> >> Err.Description, MsgBoxStyle.Critical)
>> >> >CloneMe = Nothing
>> >> >End Try
>> >> >End Function
>> >> >The red/asterisked line above is the line that generates this error.
>> >> >Ben Hannon
>> >> >"Ben Hannon" <hannon@brodart.com> wrote in message
>> >> news:eSosGI$kDHA.1656@tk2msftngp13.phx.gbl...
>> >> >> Actually, those links helped me decide to kill trying to pass the[/color][/color]
>VBA[color=green][color=darkred]
>> >> >> Collection since I can't serialize it. What I decided to do[/color][/color][/color]
instead[color=blue][color=green]
>> is[color=darkred]
>> >> to
>> >> >> create a VB.NET collection with the ArrayList class and expose the
>> >> methods
>> >> >> needed for COM Interop. Everything works perfectly when running[/color][/color][/color]
the[color=blue][color=green][color=darkred]
>> >> Class
>> >> >> as a Console App (clone works perfectly). However, when I compile[/color][/color][/color]
it[color=blue][color=green]
>> as[color=darkred]
>> >a
>> >> >> DLL and try to use it in my VB6 app, when I try to clone an object[/color][/color][/color]
I[color=blue][color=green][color=darkred]
>> >get
>> >> the
>> >> >> error "Cannot find the assembly TartanCls, Version=1.0.1384.16492,
>> >> >> Culture=neutral, PublicKeyToken=null." Any ideas?
>> >> >>
>> >> >> Ben Hannon
>> >> >>
>> >> >> "Ben Hannon" <hannon@brodart.com> wrote in message
>> >> >> news:eQExldlkDHA.964@TK2MSFTNGP10.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[/color][/color]
>that[color=green][color=darkred]
>> >> >> exposes
>> >> >> > those objects to COM perfectly. However I ran into a problem[/color]
>> because[color=darkred]
>> >> some
>> >> >> > of these objects requires a Collection. When I compile this[/color][/color]
>project[color=green][color=darkred]
>> >> with
>> >> >> > the VB.NET Collection exposed for a property, I get a compile[/color][/color][/color]
time[color=blue][color=green][color=darkred]
>> >> error
>> >> >> > that VB cann't find Type Library "Microsoft.VisualBasic". I[/color][/color][/color]
even[color=blue][color=green][color=darkred]
>> >> tried
>> >> >> > using VBA.CollectionClass, but everytime I try to create a new[/color]
>> object[color=darkred]
>> >> in
>> >> >> > VB6, the object stays equal to nothing (Doesn't create).
>> >> >> >
>> >> >> > Ben Hannon
>> >> >> > Williamsport, PA
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>
>> >> >
>> >>
>> >
>> >
>> >[/color]
>>[/color]
>
>
>[/color]

台灣微軟技術處支援工程師
Guest
 
Posts: n/a
#12: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Hi Ben,

You may try to follow the steps below let your program works.
1. copy the TartanCls.dll to your VB project directory.
2. run the regasm TartanCls.dll /tlb in the VB project directory.
3. compile the VB project and run it.
Here is my code, you may have a try.
Private Sub Command1_Click()
Dim o As tartancls.ColDataStruct
Set o = New tartancls.ColDataStruct
o.ColName = "hello"
Dim b As tartancls.ColDataStruct
Set b = o.Clone()
MsgBox b.ColName
Dim se As New tartancls.Settings
se.Save o, "c:\test.dat"
Dim c As tartancls.ColDataStruct
Set c = se.Load("c:\test.dat")
MsgBox c.ColName
End Sub

[Note if you want to run the VB project in IDE, please copy the
TartanCls.dll into the directory where VB6.exe located.]


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.
--------------------[color=blue]
>X-Tomcat-ID: 281023409
>References: <eQExldlkDHA.964@TK2MSFTNGP10.phx.gbl>[/color]
<eSosGI$kDHA.1656@tk2msftngp13.phx.gbl>
<##WFM6$kDHA.2424@TK2MSFTNGP10.phx.gbl>
<sIGw4SNlDHA.2148@cpmsftngxa06.phx.gbl>
<eqWAFEOlDHA.2216@TK2MSFTNGP12.phx.gbl>
<2duTFStlDHA.2452@cpmsftngxa06.phx.gbl>
<#PSsJJxlDHA.1884@TK2MSFTNGP09.phx.gbl>[color=blue]
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit
>From: v-phuang@online.microsoft.com (Peter Huang [MSFT])
>Organization: Microsoft
>Date: Tue, 21 Oct 2003 11:37:47 GMT
>Subject: Re: VB.NET COLLECTION VB6 COM
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>Message-ID: <PK6qCf8lDHA.1544@cpmsftngxa06.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>Lines: 442
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148623
>NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
>
>Hi Ben,
>
>Can you post a sample that will reproduce the problem, so that I can
>reproduce the problem on my machine? I will appreciate your efforts, or[/color]
you[color=blue]
>can email to me as an attachment.
>You can email to my email with the "online" removed.
>
>The code I post in my last post works on my machine, is that what you want
>to do?
>That is why I hope you can post your code, so that I can troubleshoot the
>problem.
>
>From your code, you use the serialize and deserialize method of the
>instance of BinaryFormatter.
>That is to say, the two methods will use the mscorlib.dll in your words.
>
>And you can load an assembly and invoke its methods in the runtime. That[/color]
is[color=blue]
>to say , you can use the another assembly's method[e.g. deserialize] in
>the runtime. But it is not recommended to serialize a object using one
>assembly and deserialized the object using another assembly.
>Here is a sample about call a loaded assembly in the runtime.
>
>[ConsoleApp.exe]
>Imports System.Reflection
>Module Module1
> Sub Main()
> Dim SampleAssembly As [Assembly]
> SampleAssembly =
>[Assembly].LoadFrom("E:\TestNewGroup\VB.NET\ClassLibrary5\bi n\ClassLibrary5[/color]
Peter Huang
Guest
 
Posts: n/a
#13: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Hi Ben,

Did my suggestion works for you?
If you have any question on this issue ,please post here.

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.

Ben Hannon
Guest
 
Posts: n/a
#14: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Peter,

Sorry, got busy with work and house closing stuff. Yes, your resolution
solved the problems. Thank you.
one other question though. I noticed if I add a property to my serialized
class that trying to load an old file
without that Property in that class causes the deserialization to fail
because the structure of the class differs.
Why couldn't the deserialization create the new type and fill in the data it
has leaving the other data that was
missing as being empty or nothing. I had created code in VB6 that did this
for me via an INI file. If the data
or item wasn't in the INI file and it was an object, I just set the item to
nothing and my code I made sure checked
my objects in runtime so I new if I could use them or not...

Ben

"Peter Huang" <v-phuang@online.microsoft.com> wrote in message
news:NwK$YhSnDHA.2896@cpmsftngxa06.phx.gbl...[color=blue]
> Hi Ben,
>
> Did my suggestion works for you?
> If you have any question on this issue ,please post here.
>
> 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.
>[/color]


Peter Huang
Guest
 
Posts: n/a
#15: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Hi Ben,

It seems that you want to implement version compatibility.

Versioning
The .NET Framework provides support for versioning and side-by-side
execution, and all classes will work across versions if the interfaces of
the classes remain the same. Since serializations deals with member
variables and not interfaces, be cautious when adding or removing member
variables to classes that will be serialized across versions. This is
especially true for classes that do not implement ISerializable. Any change
of state of the current version, such as the addition of member variables,
changing the types of variables, or changing their names, will mean that
existing objects of the same type cannot be successfully deserialized if
they were serialized with a previous version.

If the state of an object needs to change between versions, class authors
have two choices:

1.Implement ISerializable. This allows you to take precise control of the
serialization and deserialization process, allowing future state to be
added and interpreted correctly during deserialization.

2.Mark nonessential member variables with the NonSerialized attribute. This
option should only be used when you expect minor changes between different
versions of a class. For example, when a new variable has been added to a
later version of a class, the variable can be marked as NonSerialized to
ensure the class remains compatible with previous versions.

You may take a look at the "Custom Serialization" section in the link below.
http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/objserializ.asp

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.

Peter Huang
Guest
 
Posts: n/a
#16: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Hi Ben,

Did you have any concern on this question?
If so, please post here.

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.

Ben Hannon
Guest
 
Posts: n/a
#17: Nov 20 '05

re: VB.NET COLLECTION VB6 COM


Peter,

Nope, I worry about Versioning at a latter time. :) Thank you so much for
your help.

Ben Hannon

"Peter Huang" <v-phuang@online.microsoft.com> wrote in message
news:L0PUPkqnDHA.2464@cpmsftngxa06.phx.gbl...[color=blue]
> Hi Ben,
>
> Did you have any concern on this question?
> If so, please post here.
>
> 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.
>[/color]


Closed Thread