Am attempting to Serialize a dynamically generated/compiled assembly to store into SQL and then subsequently extract the assembly for use. However, I am hitting an error that is driving me nuts.
"Could not load file or assembly '<random code>, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
When I try to De-Serialize the Assembly. Will appreciate any pointers. Partial codes:
'--------------------------------------------------------------
'This section SUCCESSFULLY Compile & Execute the Dynamic Code
' vsResult returns ok.
' **Note: This is partial code to create the compiler.
'--------------------------------------------------------------
Dim voCompileResults As System.CodeDom.Compiler.CompilerResults = voCompiler.CompileAssemblyFromSource(voCompilerParams, sb.ToString)
Dim voAssembly As Reflection.Assembly = voCompileResults.CompiledAssembly
Dim voInstance As Object = Activator.CreateInstance(voAssembly.GetType("libARules.clsMyRoutine"), {New libARules.Sys.clsInterProcessData(New System.Xml.XmlDocument), New libArrowOps.clsDBAccess})
Dim vsResult As String = voInstance.GetType().InvokeMember("Run", Reflection.BindingFlags.InvokeMethod, Nothing, voInstance, Nothing)
'----------------------------------------------------
'Attempt to Serialize the Assembly for store/forward
'----------------------------------------------------
Dim voMemStream As New IO.MemoryStream
Dim voBF As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
voBF.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
voBF.Serialize(voMemStream, voCompileResults.CompiledAssembly)
'--------------------------------------
'Reset the MemoryStream position to begining
'--------------------------------------
voMemStream.Position = 0
'--------------------------------------
'Attempt to De-Serialize the MemoryStream back to an assembly
'--------------------------------------
voBF = New Runtime.Serialization.Formatters.Binary.BinaryFormatter
voBF.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
voAssembly = voBF.Deserialize(voMemStream)
'----- **Error Here** ---------------------------------
ERROR At this point: at the line voAssembly = voBF.Deserialize(voMemStream)
Could not load file or assembly '...<random code>..., Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.