I could not see any reason why I could not do a binary read from within a dll either. This is a snippet of what I was trying to do. It could write OK (I checked it in a hex veiwer) but raised an exception when I tried to read it back. Oddly it works when the solution is an exe.
<Serializable()> _
Public Structure solidBeamPocket
Dim angle As Double
Dim assemblyOrder As Integer
Dim blockDefHnd As String
Dim blockRefHnd As String
Dim built As Boolean
Dim centroid As Object
Dim centroidHnd As String
Dim centerLineHnd As String
Dim crippleHnd() As String
Dim crippleLength As Double
Dim crippleQty As Integer
Dim desiredElevation As Double
Dim exists As Boolean
Dim exterior As Boolean
Dim floor As Integer
Dim height As Double
Dim hiLimit As Double
Dim offset As Double
Dim offsetDirection As Boolean
Dim offsetFromObjectPosition As Integer '0 Left, 1 Center, 2 Right
Dim openHnd As String
Dim position As Integer'0-left 1-center 2-right
Dim realOffset As Double
Dim ref As Integer
Dim refTextHnd As String
Dim symbolHnd As String
Dim standerdElevation As Double
Dim studHnd() As String
Dim studLength As Double
Dim studQty As Integer
Dim studWidth As Double
Dim style As Integer
Dim wall As Integer
Dim wallOfs As Double
Dim weight As Double
Dim width As Double
Dim widthAdjust As Double
Sub New(ByVal a1 As Integer, ByVal b1 As Integer, ByVal b2 As Integer)
crippleHnd = New String(11) {}
studHnd = New String(1) {}
End Sub
End Structure
Friend Sub initStructures()
............
Dim i As Integer = 0
For i = 0 To 200
bp(i) = New solidBeamPocket(1, 1, 1)
Next i
End Sub
Public Sub dataBeamPocket(ByVal store As Boolean)
Select Case store
Case True
Dim bf As New BinaryFormatter()
Dim fs As New IO.FileStream("t:\projects\frameWhore\data\beampocket.dat", IO.FileMode.Create)
bf.Serialize(fs, bp)
fs.Close()
fs = Nothing
bf = Nothing
Case False
Dim bf As New BinaryFormatter()
Dim fs As New IO.FileStream("t:\projects\frameWhore\data\beampocket.dat", IO.FileMode.Open)
bp = DirectCast(bf.Deserialize(fs), solidBeamPocket())
fs.Close()
fs = Nothing
bf = Nothing
End Select
End Sub
When I try to read the structure back from the binary file.........
System.Runtime.Serialization.SerializationException was unhandled by user code
Message="Unable to find assembly 'frmWhr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
Source="mscorlib"
StackTrace:
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.BinaryConverter.TypeFromInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, InternalPrimitiveTypeE& primitiveTypeEnum, String& typeString, Type& type, Boolean& isVariant)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadArray(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at frmWhr.Structures.dataBeamPocket(Boolean store)
at frmWhr.Structures.initStructures()
at frmWhr.frmWhr.Form1.cmdDirectionSouthWest_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)