473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.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
Nov 20 '05 #1
16 2557
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.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 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.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


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

Ben Hannon

"Ben Hannon" <ha****@brodart.com> wrote in message
news:eQ*************@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 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

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

Ben Hannon

"Ben Hannon" <ha****@brodart.com> wrote in message
news:eQ*************@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 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

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.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" <ha****@brodart.com> wrote in message news:eS**************@tk2msftngp13.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.1384.16492,
Culture=neutral, PublicKeyToken=null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart.com> wrote in message
news:eQ*************@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 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


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

--------------------
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.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: <##**************@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 when I tryto 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" <ha****@brodart.com> wrote in message

news:eS**************@tk2msftngp13.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.1384.16492,
Culture=neutral, PublicKeyToken=null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart.com> wrote in message
news:eQ*************@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 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
>
>



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.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-******@online.microsoft.com> wrote in message
news:sI**************@cpmsftngxa06.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.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.

--------------------
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.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: <##**************@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

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" <ha****@brodart.com> wrote in message

news:eS**************@tk2msftngp13.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.1384.16492,
Culture=neutral, PublicKeyToken=null." Any ideas?

Ben Hannon

"Ben Hannon" <ha****@brodart.com> wrote in message
news:eQ*************@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 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
>
>

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.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.
--------------------
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.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 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.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 Itried
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-******@online.microsoft.com> wrote in message
news:sI**************@cpmsftngxa06.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.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.
--------------------
>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.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: <##**************@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

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" <ha****@brodart.com> wrote in message

news:eS**************@tk2msftngp13.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.1384.16492,
>> Culture=neutral, PublicKeyToken=null." Any ideas?
>>
>> Ben Hannon
>>
>> "Ben Hannon" <ha****@brodart.com> wrote in message
>> news:eQ*************@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 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
>> >
>> >
>>
>>
>



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.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-******@online.microsoft.com> wrote in message
news:2d**************@cpmsftngxa06.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.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.
--------------------
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.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

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

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.microsoft.com> wrote in message
news:sI**************@cpmsftngxa06.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.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.
--------------------
>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.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: <##**************@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 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" <ha****@brodart.com> wrote in message
news:eS**************@tk2msftngp13.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.1384.16492,
>> Culture=neutral, PublicKeyToken=null." Any ideas?
>>
>> Ben Hannon
>>
>> "Ben Hannon" <ha****@brodart.com> wrote in message
>> news:eQ*************@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 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
>> >
>> >
>>
>>
>


Nov 20 '05 #10
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.
--------------------
From: "Ben Hannon" <ha****@brodart.com>
References: <eQ*************@TK2MSFTNGP10.phx.gbl> <eS**************@tk2msftngp13.phx.gbl>
<##**************@TK2MSFTNGP10.phx.gbl>
<sI**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP12.phx.gbl>
<2d**************@cpmsftngxa06.phx.gbl>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: <#P**************@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-******@online.microsoft.com> wrote in message
news:2d**************@cpmsftngxa06.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.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.
--------------------
>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.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

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 thatwas >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 DLLto >loop through the AppDomain.CurrentDomain.GetAssemblies and msgbox the
>assembly info to check if the assembly was loaded and it was, howeverwhen
I
>tried


Path.GetDirectoryName(System.Reflection.Assbly.G etEntryAssembly().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 assemblya >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 copyingthe >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.microsoft.com> wrote in message
>news:sI**************@cpmsftngxa06.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 fromVB >to
>> NET is an COM object.
>> The serialization implement between COM and .NET is different, that isto >> 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.
>>
>> --------------------
>> >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.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: <##**************@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 isoccurring >> 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" <ha****@brodart.com> wrote in message
>> news:eS**************@tk2msftngp13.phx.gbl...
>> >> Actually, those links helped me decide to kill trying to pass theVBA >> >> 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" <ha****@brodart.com> wrote in message
>> >> news:eQ*************@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

that >> >> exposes
>> >> > those objects to COM perfectly. However I ran into a problem

because
>> some
>> >> > of these objects requires a Collection. When I compile thisproject >> 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
>> >> >
>> >> >
>> >>
>> >>
>> >
>>
>
>
>



Nov 20 '05 #11
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.
--------------------
X-Tomcat-ID: 281023409
References: <eQ*************@TK2MSFTNGP10.phx.gbl> <eS**************@tk2msftngp13.phx.gbl>
<##**************@TK2MSFTNGP10.phx.gbl>
<sI**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP12.phx.gbl>
<2d**************@cpmsftngxa06.phx.gbl>
<#P**************@TK2MSFTNGP09.phx.gbl>MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: v-******@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: <PK**************@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 youcan 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 isto 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

Nov 20 '05 #12
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.

Nov 20 '05 #13
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-******@online.microsoft.com> wrote in message
news:Nw**************@cpmsftngxa06.phx.gbl...
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.

Nov 20 '05 #14
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.

Nov 20 '05 #15
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.

Nov 20 '05 #16
Peter,

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

Ben Hannon

"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:L0**************@cpmsftngxa06.phx.gbl...
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.

Nov 20 '05 #17

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

Similar topics

8
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...
5
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...
18
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...
11
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...
2
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...
6
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...
3
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...
10
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...
6
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...
6
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.