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" <
[email protected]>
References: <
[email protected]>
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: <##
[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 12.29.184.66
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.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
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