Working in Visual Studio, I'm trying to pass an entire row to a CLR stored procedure using FOR XML RAW and a parameter of type SqlXml in C# code (with the intent of processing the row using XmlReader). The row contains nvarchar fields.
Everything works correctly when the nvarchar fields contain English/numeric/simple punctuation text, but when any of them contain Hebrew or Russian characters, these characters are turned into question marks. (The same for Russian-only text so not an RTL issue)
From prints in SQL code I've found that the xml created by XML RAW preserves the non-English characters - they are printed just fine. But when printing sqlXmlParameter.Value (or putting it in output string and printing that in sql) question marks are printed instead of the non-English characters. I've tried using an SqlString parameter and got the same result - the parameter looks fine in SQL, but changes when passed to CLR procedure.
I've also found that both T-SQL and C# use UTF-16 as default encoding, so this is really weird.
How can I preserve non-English characters when passing parameters to CLR, or attach encoding information to them?
Edit: This Question relates to the following: How to make SqlContext.Pipe.Send in SQLCLR stored proc work with unicode? As it turns out, the solution to the other question solved this issue as well. I'm not sure why, since the C# code in this case contained no non-English characters, but it did use string formatting with strings that could be non-English, so maybe some mix of encodings was caused because of how the constants in the string format were saved. Just my guess though. So in case someone runs into a related problem (despite my vague definition of it) you might want to try that.