Loading a file on the compact framework saved from asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've created a file on an iis web server using asp.net which saves multiple structures into a file. When I try and read it in through the compact framework, it's not loading properly. The structures aren't being populated. I'm just wondering if it's a problem with the strings not being read as they should be
If it is unicode strings causing the problem, then how do I convert the string data to unicode before saving the file
I'm using a FileStream to do all the reading and writing at byte level in vb.net
Any ideas
 
Make sure that you are specifying correct encoding when creating a
BinaryReader object

--
Alex Feinman
---
Visit http://www.opennetcf.org
BaXt0R said:
I've created a file on an iis web server using asp.net which saves
multiple structures into a file. When I try and read it in through the
compact framework, it's not loading properly. The structures aren't being
populated. I'm just wondering if it's a problem with the strings not being
read as they should be.
If it is unicode strings causing the problem, then how do I convert the
string data to unicode before saving the file.
 
I wasn't using a BinaryWriter in the first place, just a straight forward FileStream. I tried using the BinaryWriter, but its still not working.

I'm using this function to convert a structure to a pointer in asp.net..

Public Function RawSerialize(ByVal anything As Object) As Byte(

Dim rawsize As Integer = Marshal.SizeOf(anything
Dim buffer As IntPtr = Marshal.AllocHGlobal(rawsize

Marshal.StructureToPtr(anything, buffer, False

Dim rawdatas(rawsize - 1) As Byt

Marshal.Copy(buffer, rawdatas, 0, rawsize
Marshal.FreeHGlobal(buffer

Return rawdata

End Functio

Here's one of the structures (defined the same in asp.net and the compact framework versions

Public Structure AuditDefinitio
Public sAuditRef As Strin
Public sAuditName As Strin
Public sAuditDescription As Strin
Public Status As StatusType
Public Version As Intege
Public dCreationDate As Dat
Public dModifiedDate As Dat
Public sAuthor As Strin
Public sFeedbackEmail As Strin
Public DefaultScore As Intege
Public YesNoNADefault As Default
End Structur

and then I'm using this to read the bytes back into the structure..

Public Function RawDeserialize(ByVal rawdatas As Byte(), ByVal anytype As Type) As Objec

Dim rawsize As Integer = Marshal.SizeOf(anytype

If (rawsize > rawdatas.Length) The
Return Nothin
End I

Dim buffer As IntPtr = LocalAlloc(Convert.ToUInt32(LMEM_FIXED Or LMEM_ZEROINIT), Convert.ToUInt32(rawsize)

Marshal.Copy(rawdatas, 0, buffer, rawsize

Dim retobj As Object = Marshal.PtrToStructure(buffer, anytype

LocalFree(buffer

Return retob

End Functio

Any ideas?
 
After a little more research I found out that the Marshal.SizeOf(structure) on the compact framework was returning a different size compared to the Marshal.SizeOf(structure) on the normal framework. Should this be happening? Are strings/integers different sizes in the two versions ???
 
Yes, it's a Unicode problem. When you save the file, you must save it using
Unicode encoding.

-Chris


BaXt0R said:
After a little more research I found out that the
Marshal.SizeOf(structure) on the compact framework was returning a different
size compared to the Marshal.SizeOf(structure) on the normal framework.
Should this be happening? Are strings/integers different sizes in the two
versions ???
 
Back
Top