I’m trying to write in a msmq file an UTF8 with Bom xml , so I created my own formatter like this (http://support.microsoft.com/kb/310683)
But in result i have an UTF8 without Bom XML So i tried this : Public Sub Write(message As System.Messaging.Message, obj As Object) Implements System.Messaging.IMessageFormatter.Write
Dim utf8 As UTF8Encoding = New UTF8Encoding(True)
Dim stm As Stream = New MemoryStream()
Dim writer As StreamWriter = New StreamWriter(stm, utf8)
writer.Write(obj.ToString())
message.BodyStream = stm
End Sub
it works but it cuts my xml and I don’t close the writer !!
Thanks in advance for your help
The problem is that the StreamWriter has buffered data which is not being flushed:
…
writer.Write(obj.ToString())
writer.Flush();
message.BodyStream = stm