view raw
jadou jadou - 6 months ago 39 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 (

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


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

message.BodyStream = stm