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]