EDN Admin
Well-known member
Hi all,
I hope this is thr right forum for this - if not please point me in the right direction and Ill move it. Anyway, Im writing a solution in VB.NET that consists of a number of different components (UI manager, Outlook add-in, etc.). In the main UI program
Im serializing out an arraylist to a data file that contains the data the other components will need to do their jobs. That part works fine, and I can serialize and deserialize with no problem. Now I want to read (deserialize ) in the data in my Outlook
add-in, and I ran into the dreaded Unable to find assembly issue where its looking for the original assembly that serialized the data. I found a hint for workaround ( http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder(VS.71).aspx http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder(VS.71).aspx <br/>
) that basically has me creating a new class that overrides the BindToType property of the SerializationBinder and returns my currently running assembly as the right one. Heres the code Im using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Runtime.Serialization
<span style="color:Blue; Imports System.Reflection
<span style="color:Blue; NotInheritable <span style="color:Blue; Class OverrideDeserializationBinding
<span style="color:Blue; Inherits SerializationBinder
<span style="color:Blue; Public <span style="color:Blue; Overrides <span style="color:Blue; Function BindToType(<span style="color:Blue; ByVal assemblyName <span style="color:Blue; As <span style="color:Blue; String, _
<span style="color:Blue; ByVal typeName <span style="color:Blue; As <span style="color:Blue; String) <span style="color:Blue; As Type
<span style="color:Blue; Dim typeToDeserialize <span style="color:Blue; As Type = <span style="color:Blue; Nothing
<span style="color:Green; For each assemblyName/typeName that you want to deserialize
<span style="color:Green; to a different type, set typeToDeserialize to the desired type.
<span style="color:Blue; Dim MyAssemblyName <span style="color:Blue; As <span style="color:Blue; String = [<span style="color:Blue; Assembly].GetExecutingAssembly().FullName
<span style="color:Green; The following code returns the type.
typeToDeserialize = Type.<span style="color:Blue; GetType(<span style="color:Blue; String.Format(<span style="color:#A31515; "{0}, {1}", typeName, MyAssemblyName))
<span style="color:Blue; Return typeToDeserialize
<span style="color:Blue; End <span style="color:Blue; Function
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
And heres how Im using it in my Outlook add-in:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Try
<span style="color:Green; Serialize in the existing Arraylist
fs = <span style="color:Blue; New FileStream(strMyAppDataFile, FileMode.Open)
bf = <span style="color:Blue; New BinaryFormatter()
bf.Binder = <span style="color:Blue; New OverrideDeserializationBinding
alEmailTableList = <span style="color:Blue; New ArrayList
alEmailTableList = <span style="color:Blue; CType(bf.Deserialize(fs), ArrayList)
fs.Close()
bf.Binder = <span style="color:Blue; Nothing
bf = <span style="color:Blue; Nothing
fs = <span style="color:Blue; Nothing
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
MsgBox(<span style="color:#A31515; "[O2TOutlookAddin] Exception loading email table data - " & ex.Message)
fs.Close()
bf.Binder = <span style="color:Blue; Nothing
bf = <span style="color:Blue; Nothing
fs = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Try
[/code]
The problem is that its not working - Im still getting the Unable to find assembly... exception with the name of the program that serialized the data originally.
Any idea what Im doing wrong?
Thanx.
John <hr class="sig John McDonald
View the full article
I hope this is thr right forum for this - if not please point me in the right direction and Ill move it. Anyway, Im writing a solution in VB.NET that consists of a number of different components (UI manager, Outlook add-in, etc.). In the main UI program
Im serializing out an arraylist to a data file that contains the data the other components will need to do their jobs. That part works fine, and I can serialize and deserialize with no problem. Now I want to read (deserialize ) in the data in my Outlook
add-in, and I ran into the dreaded Unable to find assembly issue where its looking for the original assembly that serialized the data. I found a hint for workaround ( http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder(VS.71).aspx http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder(VS.71).aspx <br/>
) that basically has me creating a new class that overrides the BindToType property of the SerializationBinder and returns my currently running assembly as the right one. Heres the code Im using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Runtime.Serialization
<span style="color:Blue; Imports System.Reflection
<span style="color:Blue; NotInheritable <span style="color:Blue; Class OverrideDeserializationBinding
<span style="color:Blue; Inherits SerializationBinder
<span style="color:Blue; Public <span style="color:Blue; Overrides <span style="color:Blue; Function BindToType(<span style="color:Blue; ByVal assemblyName <span style="color:Blue; As <span style="color:Blue; String, _
<span style="color:Blue; ByVal typeName <span style="color:Blue; As <span style="color:Blue; String) <span style="color:Blue; As Type
<span style="color:Blue; Dim typeToDeserialize <span style="color:Blue; As Type = <span style="color:Blue; Nothing
<span style="color:Green; For each assemblyName/typeName that you want to deserialize
<span style="color:Green; to a different type, set typeToDeserialize to the desired type.
<span style="color:Blue; Dim MyAssemblyName <span style="color:Blue; As <span style="color:Blue; String = [<span style="color:Blue; Assembly].GetExecutingAssembly().FullName
<span style="color:Green; The following code returns the type.
typeToDeserialize = Type.<span style="color:Blue; GetType(<span style="color:Blue; String.Format(<span style="color:#A31515; "{0}, {1}", typeName, MyAssemblyName))
<span style="color:Blue; Return typeToDeserialize
<span style="color:Blue; End <span style="color:Blue; Function
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
And heres how Im using it in my Outlook add-in:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Try
<span style="color:Green; Serialize in the existing Arraylist
fs = <span style="color:Blue; New FileStream(strMyAppDataFile, FileMode.Open)
bf = <span style="color:Blue; New BinaryFormatter()
bf.Binder = <span style="color:Blue; New OverrideDeserializationBinding
alEmailTableList = <span style="color:Blue; New ArrayList
alEmailTableList = <span style="color:Blue; CType(bf.Deserialize(fs), ArrayList)
fs.Close()
bf.Binder = <span style="color:Blue; Nothing
bf = <span style="color:Blue; Nothing
fs = <span style="color:Blue; Nothing
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
MsgBox(<span style="color:#A31515; "[O2TOutlookAddin] Exception loading email table data - " & ex.Message)
fs.Close()
bf.Binder = <span style="color:Blue; Nothing
bf = <span style="color:Blue; Nothing
fs = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Try
[/code]
The problem is that its not working - Im still getting the Unable to find assembly... exception with the name of the program that serialized the data originally.
Any idea what Im doing wrong?
Thanx.
John <hr class="sig John McDonald
View the full article