jadou jadou - 1 year ago 107
Vb.net Question

Write in MSMQ file an XML encoded in UTF8 With Bom

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)
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

Answer Source

The problem is that the StreamWriter has buffered data which is not being flushed:

message.BodyStream = stm
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download